| 1 |
/* gstreamermm - a C++ wrapper for gstreamer |
| 2 |
* |
| 3 |
* Copyright 2014-2015 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/memory.h> |
| 21 |
|
| 22 |
_PINCLUDE(gstreamermm/private/object_p.h) |
| 23 |
|
| 24 |
namespace Gst |
| 25 |
{ |
| 26 |
AllocationParams::AllocationParams() |
| 27 |
{ |
| 28 |
GstAllocationParams params; |
| 29 |
gst_allocation_params_init(¶ms); |
| 30 |
gobject_ = gst_allocation_params_copy(¶ms); |
| 31 |
} |
| 32 |
|
| 33 |
Glib::RefPtr<Gst::Allocator> Allocator::get_default_allocator() |
| 34 |
{ |
| 35 |
return Glib::wrap(gst_allocator_find(nullptr), false); |
| 36 |
} |
| 37 |
|
| 38 |
void Allocator::set_default() |
| 39 |
{ |
| 40 |
reference(); |
| 41 |
gst_allocator_set_default(gobj()); |
| 42 |
} |
| 43 |
|
| 44 |
void Allocator_Class::free_vfunc_callback(GstAllocator* self, GstMemory* memory) |
| 45 |
{ |
| 46 |
Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>( |
| 47 |
Glib::ObjectBase::_get_current_wrapper((GObject*)self)); |
| 48 |
|
| 49 |
// Non-gtkmmproc-generated custom classes implicitly call the default |
| 50 |
// Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc- |
| 51 |
// generated classes can use this optimisation, which avoids the unnecessary |
| 52 |
// parameter conversions if there is no possibility of the virtual function |
| 53 |
// being overridden: |
| 54 |
if(obj_base && obj_base->is_derived_()) |
| 55 |
{ |
| 56 |
CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base); |
| 57 |
if(obj) // This can be NULL during destruction. |
| 58 |
{ |
| 59 |
#ifdef GLIBMM_EXCEPTIONS_ENABLED |
| 60 |
try // Trap C++ exceptions which would normally be lost because this is a C callback. |
| 61 |
{ |
| 62 |
#endif //GLIBMM_EXCEPTIONS_ENABLED |
| 63 |
// Call the virtual member method, which derived classes might override. |
| 64 |
Glib::RefPtr<Gst::Memory> mem = Glib::wrap(memory); |
| 65 |
obj->free_vfunc(std::move(mem)); |
| 66 |
return; |
| 67 |
#ifdef GLIBMM_EXCEPTIONS_ENABLED |
| 68 |
} |
| 69 |
catch(...) |
| 70 |
{ |
| 71 |
Glib::exception_handlers_invoke(); |
| 72 |
} |
| 73 |
#endif //GLIBMM_EXCEPTIONS_ENABLED |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
BaseClassType *const base = static_cast<BaseClassType*>( |
| 78 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class). |
| 79 |
); |
| 80 |
|
| 81 |
// Call the original underlying C function: |
| 82 |
if(base && base->free) |
| 83 |
{ |
| 84 |
(*base->free)(self, memory); |
| 85 |
} |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
void Gst::Allocator::free_vfunc(Glib::RefPtr<Gst::Memory>&& memory) |
| 90 |
{ |
| 91 |
BaseClassType *const base = static_cast<BaseClassType*>( |
| 92 |
g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) |
| 93 |
); |
| 94 |
|
| 95 |
if(base && base->free) |
| 96 |
{ |
| 97 |
GstMemory* mem_gobj = memory.release()->gobj(); |
| 98 |
(*base->free)(gobj(), mem_gobj); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
} |