| 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/caps.h> |
| 21 |
#include <gstreamermm/buffer.h> |
| 22 |
|
| 23 |
_PINCLUDE(gstreamermm/private/element_p.h) |
| 24 |
|
| 25 |
#define IGNORE_RESULT(x) { auto release_value = x; (void)release_value; } |
| 26 |
|
| 27 |
namespace Gst |
| 28 |
{ |
| 29 |
|
| 30 |
gboolean BaseSrc_Class::do_seek_vfunc_callback(GstBaseSrc* self, GstSegment* segment) |
| 31 |
{ |
| 32 |
Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>( |
| 33 |
Glib::ObjectBase::_get_current_wrapper((GObject*)self)); |
| 34 |
|
| 35 |
// Non-gtkmmproc-generated custom classes implicitly call the default |
| 36 |
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc- |
| 37 |
// generated classes can use this optimisation, which avoids the unnecessary |
| 38 |
// parameter conversions if there is no possibility of the virtual function |
| 39 |
// being overridden: |
| 40 |
if(obj_base && obj_base->is_derived_()) |
| 41 |
{ |
| 42 |
CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base); |
| 43 |
if(obj) // This can be NULL during destruction. |
| 44 |
{ |
| 45 |
try // Trap C++ exceptions which would normally be lost because this is a C callback. |
| 46 |
{ |
| 47 |
Gst::Segment cpp_segment(segment, true); |
| 48 |
// Call the virtual member method, which derived classes might override. |
| 49 |
return static_cast<int>(obj->do_seek_vfunc(cpp_segment)); |
| 50 |
} |
| 51 |
catch(...) |
| 52 |
{ |
| 53 |
Glib::exception_handlers_invoke(); |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
BaseClassType *const base = static_cast<BaseClassType*>( |
| 59 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 60 |
); |
| 61 |
|
| 62 |
// Call the original underlying C function: |
| 63 |
if(base && base->do_seek) |
| 64 |
return (*base->do_seek)(self, segment); |
| 65 |
|
| 66 |
|
| 67 |
typedef gboolean RType; |
| 68 |
return RType(); |
| 69 |
} |
| 70 |
bool Gst::BaseSrc::do_seek_vfunc(Gst::Segment& segment) |
| 71 |
{ |
| 72 |
BaseClassType *const base = static_cast<BaseClassType*>( |
| 73 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class). |
| 74 |
); |
| 75 |
|
| 76 |
if(base && base->do_seek) |
| 77 |
return (*base->do_seek)(gobj(),(segment).gobj()); |
| 78 |
|
| 79 |
typedef bool RType; |
| 80 |
return RType(); |
| 81 |
} |
| 82 |
gboolean BaseSrc_Class::prepare_seek_segment_vfunc_callback(GstBaseSrc* self, GstEvent* seek, GstSegment* segment) |
| 83 |
{ |
| 84 |
Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>( |
| 85 |
Glib::ObjectBase::_get_current_wrapper((GObject*)self)); |
| 86 |
|
| 87 |
// Non-gtkmmproc-generated custom classes implicitly call the default |
| 88 |
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc- |
| 89 |
// generated classes can use this optimisation, which avoids the unnecessary |
| 90 |
// parameter conversions if there is no possibility of the virtual function |
| 91 |
// being overridden: |
| 92 |
if(obj_base && obj_base->is_derived_()) |
| 93 |
{ |
| 94 |
CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base); |
| 95 |
if(obj) // This can be NULL during destruction. |
| 96 |
{ |
| 97 |
try // Trap C++ exceptions which would normally be lost because this is a C callback. |
| 98 |
{ |
| 99 |
// Call the virtual member method, which derived classes might override. |
| 100 |
Gst::Segment cpp_segment(segment, true); |
| 101 |
return static_cast<int>(obj->prepare_seek_segment_vfunc(Glib::wrap(seek, true) , cpp_segment)); |
| 102 |
} |
| 103 |
catch(...) |
| 104 |
{ |
| 105 |
Glib::exception_handlers_invoke(); |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
BaseClassType *const base = static_cast<BaseClassType*>( |
| 111 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 112 |
); |
| 113 |
|
| 114 |
// Call the original underlying C function: |
| 115 |
if(base && base->prepare_seek_segment) |
| 116 |
return (*base->prepare_seek_segment)(self, seek, segment); |
| 117 |
|
| 118 |
|
| 119 |
typedef gboolean RType; |
| 120 |
return RType(); |
| 121 |
} |
| 122 |
bool Gst::BaseSrc::prepare_seek_segment_vfunc(const Glib::RefPtr<Gst::Event>& seek, Gst::Segment& segment) |
| 123 |
{ |
| 124 |
BaseClassType *const base = static_cast<BaseClassType*>( |
| 125 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class). |
| 126 |
); |
| 127 |
|
| 128 |
if(base && base->prepare_seek_segment) |
| 129 |
return (*base->prepare_seek_segment)(gobj(),Glib::unwrap(seek),(segment).gobj()); |
| 130 |
|
| 131 |
typedef bool RType; |
| 132 |
return RType(); |
| 133 |
} |
| 134 |
GstFlowReturn BaseSrc_Class::create_vfunc_callback(GstBaseSrc* self, guint64 offset, guint size, GstBuffer** buf) |
| 135 |
{ |
| 136 |
Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>( |
| 137 |
Glib::ObjectBase::_get_current_wrapper((GObject*)self)); |
| 138 |
|
| 139 |
// Non-gtkmmproc-generated custom classes implicitly call the default |
| 140 |
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc- |
| 141 |
// generated classes can use this optimisation, which avoids the unnecessary |
| 142 |
// parameter conversions if there is no possibility of the virtual function |
| 143 |
// being overridden: |
| 144 |
if(obj_base && obj_base->is_derived_()) |
| 145 |
{ |
| 146 |
CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base); |
| 147 |
if(obj) // This can be NULL during destruction. |
| 148 |
{ |
| 149 |
try // Trap C++ exceptions which would normally be lost because this is a C callback. |
| 150 |
{ |
| 151 |
Glib::RefPtr<Gst::Buffer> cpp_buffer; |
| 152 |
// Call the virtual member method, which derived classes might override. |
| 153 |
GstFlowReturn const result = static_cast<GstFlowReturn>(obj->create_vfunc(offset, size, cpp_buffer)); |
| 154 |
*buf = cpp_buffer ? cpp_buffer->gobj_copy() : 0; |
| 155 |
return result; |
| 156 |
} |
| 157 |
catch(...) |
| 158 |
{ |
| 159 |
Glib::exception_handlers_invoke(); |
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
BaseClassType *const base = static_cast<BaseClassType*>( |
| 165 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 166 |
); |
| 167 |
|
| 168 |
// Call the original underlying C function: |
| 169 |
if(base && base->create) |
| 170 |
return (*base->create)(self, offset, size, buf); |
| 171 |
|
| 172 |
|
| 173 |
typedef GstFlowReturn RType; |
| 174 |
return RType(); |
| 175 |
} |
| 176 |
FlowReturn Gst::BaseSrc::create_vfunc(guint64 offset, guint size, Glib::RefPtr<Gst::Buffer>& buffer) |
| 177 |
{ |
| 178 |
BaseClassType *const base = static_cast<BaseClassType*>( |
| 179 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class). |
| 180 |
); |
| 181 |
|
| 182 |
if(base && base->create) |
| 183 |
{ |
| 184 |
GstBuffer* gst_buffer = NULL; |
| 185 |
Gst::FlowReturn const result = |
| 186 |
static_cast<FlowReturn>((*base->create)(gobj(),offset, size,&gst_buffer)); |
| 187 |
buffer = Glib::wrap(gst_buffer, false); // Don't take copy because callback returns a newly created copy. |
| 188 |
return result; |
| 189 |
} |
| 190 |
|
| 191 |
typedef FlowReturn RType; |
| 192 |
return RType(); |
| 193 |
} |
| 194 |
|
| 195 |
Glib::RefPtr<Allocator> BaseSrc::get_allocator(AllocationParams& params) |
| 196 |
{ |
| 197 |
GstAllocator* alloc; |
| 198 |
gst_base_src_get_allocator(gobj(), &alloc, params.gobj()); |
| 199 |
return Glib::wrap(alloc, false); |
| 200 |
} |
| 201 |
|
| 202 |
gboolean BaseSrc_Class::query_vfunc_callback(GstBaseSrc* self, GstQuery* query) |
| 203 |
{ |
| 204 |
const auto obj_base = static_cast<Glib::ObjectBase*>( |
| 205 |
Glib::ObjectBase::_get_current_wrapper((GObject*)self)); |
| 206 |
|
| 207 |
// Non-gtkmmproc-generated custom classes implicitly call the default |
| 208 |
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc- |
| 209 |
// generated classes can use this optimisation, which avoids the unnecessary |
| 210 |
// parameter conversions if there is no possibility of the virtual function |
| 211 |
// being overridden: |
| 212 |
if(obj_base && obj_base->is_derived_()) |
| 213 |
{ |
| 214 |
const auto obj = dynamic_cast<CppObjectType* const>(obj_base); |
| 215 |
if(obj) // This can be NULL during destruction. |
| 216 |
{ |
| 217 |
try // Trap C++ exceptions which would normally be lost because this is a C callback. |
| 218 |
{ |
| 219 |
// Call the virtual member method, which derived classes might override. |
| 220 |
auto query_cpp = Glib::wrap(query, false); |
| 221 |
int ret = static_cast<int>(obj->base_src_query_vfunc(query_cpp)); |
| 222 |
IGNORE_RESULT(query_cpp.release()); |
| 223 |
return ret; |
| 224 |
} |
| 225 |
catch(...) |
| 226 |
{ |
| 227 |
Glib::exception_handlers_invoke(); |
| 228 |
} |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
BaseClassType *const base = static_cast<BaseClassType*>( |
| 233 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 234 |
); |
| 235 |
|
| 236 |
// Call the original underlying C function: |
| 237 |
if(base && base->query) |
| 238 |
{ |
| 239 |
gboolean retval = (*base->query)(self, query); |
| 240 |
return retval; |
| 241 |
} |
| 242 |
|
| 243 |
typedef gboolean RType; |
| 244 |
return RType(); |
| 245 |
} |
| 246 |
|
| 247 |
bool Gst::BaseSrc::base_src_query_vfunc(const Glib::RefPtr<Gst::Query>& query) |
| 248 |
{ |
| 249 |
const auto base = static_cast<BaseClassType*>( |
| 250 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class). |
| 251 |
); |
| 252 |
|
| 253 |
if(base && base->query) |
| 254 |
{ |
| 255 |
bool retval((*base->query)(const_cast<GstBaseSrc*>(gobj()),Glib::unwrap(query))); |
| 256 |
return retval; |
| 257 |
} |
| 258 |
|
| 259 |
typedef bool RType; |
| 260 |
return RType(); |
| 261 |
} |
| 262 |
|
| 263 |
GstFlowReturn BaseSrc_Class::alloc_vfunc_callback(GstBaseSrc* self, guint64 offset, guint size, GstBuffer** buf) |
| 264 |
{ |
| 265 |
Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>( |
| 266 |
Glib::ObjectBase::_get_current_wrapper((GObject*)self)); |
| 267 |
|
| 268 |
// Non-gtkmmproc-generated custom classes implicitly call the default |
| 269 |
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc- |
| 270 |
// generated classes can use this optimisation, which avoids the unnecessary |
| 271 |
// parameter conversions if there is no possibility of the virtual function |
| 272 |
// being overridden: |
| 273 |
if(obj_base && obj_base->is_derived_()) |
| 274 |
{ |
| 275 |
CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base); |
| 276 |
if(obj) // This can be NULL during destruction. |
| 277 |
{ |
| 278 |
try // Trap C++ exceptions which would normally be lost because this is a C callback. |
| 279 |
{ |
| 280 |
Glib::RefPtr<Gst::Buffer> cpp_buffer; |
| 281 |
// Call the virtual member method, which derived classes might override. |
| 282 |
GstFlowReturn const result = static_cast<GstFlowReturn>(obj->alloc_vfunc(offset, size, cpp_buffer)); |
| 283 |
*buf = cpp_buffer ? cpp_buffer->gobj_copy() : 0; |
| 284 |
return result; |
| 285 |
} |
| 286 |
catch(...) |
| 287 |
{ |
| 288 |
Glib::exception_handlers_invoke(); |
| 289 |
} |
| 290 |
} |
| 291 |
} |
| 292 |
|
| 293 |
BaseClassType *const base = static_cast<BaseClassType*>( |
| 294 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 295 |
); |
| 296 |
|
| 297 |
// Call the original underlying C function: |
| 298 |
if(base && base->alloc) |
| 299 |
return (*base->alloc)(self, offset, size, buf); |
| 300 |
|
| 301 |
|
| 302 |
typedef GstFlowReturn RType; |
| 303 |
return RType(); |
| 304 |
} |
| 305 |
FlowReturn Gst::BaseSrc::alloc_vfunc(guint64 offset, guint size, Glib::RefPtr<Gst::Buffer>& buffer) |
| 306 |
{ |
| 307 |
BaseClassType *const base = static_cast<BaseClassType*>( |
| 308 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class). |
| 309 |
); |
| 310 |
|
| 311 |
if(base && base->alloc) |
| 312 |
{ |
| 313 |
GstBuffer* gst_buffer = NULL; |
| 314 |
Gst::FlowReturn const result = |
| 315 |
static_cast<FlowReturn>((*base->alloc)(gobj(),offset, size,&gst_buffer)); |
| 316 |
buffer = Glib::wrap(gst_buffer, false); // Don't take copy because callback returns a newly created copy. |
| 317 |
return result; |
| 318 |
} |
| 319 |
|
| 320 |
typedef FlowReturn RType; |
| 321 |
return RType(); |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
} // namespace Gst |