| 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 <gst/gst.h> |
| 21 |
#include <gstreamermm/value.h> |
| 22 |
#include <gstreamermm/miniobject.h> |
| 23 |
|
| 24 |
namespace |
| 25 |
{ |
| 26 |
|
| 27 |
static Glib::ustring quark_to_ustring(GQuark quark) |
| 28 |
{ |
| 29 |
const gchar* pch = g_quark_to_string(quark); |
| 30 |
Glib::ustring str; |
| 31 |
if(pch) |
| 32 |
str = pch; |
| 33 |
|
| 34 |
return str; |
| 35 |
} |
| 36 |
|
| 37 |
extern "C" |
| 38 |
{ |
| 39 |
|
| 40 |
static gboolean |
| 41 |
Structure_Foreach_gstreamermm_callback(GQuark field_id, const GValue *value, void* data) |
| 42 |
{ |
| 43 |
Gst::Structure::SlotForeach* slot = static_cast<Gst::Structure::SlotForeach*>(data); |
| 44 |
|
| 45 |
try |
| 46 |
{ |
| 47 |
return (*slot)(quark_to_ustring(field_id), *reinterpret_cast<const Glib::ValueBase*>(value)); |
| 48 |
} |
| 49 |
catch(...) |
| 50 |
{ |
| 51 |
Glib::exception_handlers_invoke(); |
| 52 |
} |
| 53 |
|
| 54 |
return false; |
| 55 |
} |
| 56 |
|
| 57 |
static gboolean |
| 58 |
Structure_Map_gstreamermm_callback(GQuark field_id, GValue *value, void* data) |
| 59 |
{ |
| 60 |
Gst::Structure::SlotMap* slot = static_cast<Gst::Structure::SlotMap*>(data); |
| 61 |
|
| 62 |
try |
| 63 |
{ |
| 64 |
bool result = (*slot)(quark_to_ustring(field_id), *reinterpret_cast<Glib::ValueBase*>(value)); |
| 65 |
return result; |
| 66 |
} |
| 67 |
catch(...) |
| 68 |
{ |
| 69 |
Glib::exception_handlers_invoke(); |
| 70 |
} |
| 71 |
|
| 72 |
return false; |
| 73 |
} |
| 74 |
|
| 75 |
} // extern "C" |
| 76 |
|
| 77 |
} // anonymous namespace |
| 78 |
|
| 79 |
namespace Gst |
| 80 |
{ |
| 81 |
|
| 82 |
Structure::operator const void*() const |
| 83 |
{ |
| 84 |
return gobject_ ? GINT_TO_POINTER(1) : nullptr; |
| 85 |
} |
| 86 |
|
| 87 |
GstStructure* Structure::release() noexcept |
| 88 |
{ |
| 89 |
GstStructure *tmp = gobj(); |
| 90 |
gobject_ = nullptr; |
| 91 |
return tmp; |
| 92 |
} |
| 93 |
|
| 94 |
void Structure::get_field(const Glib::ustring& name, Glib::ValueBase& value) const |
| 95 |
{ |
| 96 |
const GValue *val = gst_structure_get_value(gobj(), name.c_str()); |
| 97 |
value.init(val); |
| 98 |
} |
| 99 |
|
| 100 |
void Structure::set_field(const Glib::ustring& fieldname, |
| 101 |
const Glib::ValueBase& value) |
| 102 |
{ |
| 103 |
gst_structure_set_value(gobj(), fieldname.c_str(), value.gobj()); |
| 104 |
} |
| 105 |
|
| 106 |
void Structure::set_field(const Glib::ustring& fieldname, GType enumtype, int value) |
| 107 |
{ |
| 108 |
gst_structure_set(gobj(), fieldname.c_str(), enumtype, value, nullptr); |
| 109 |
} |
| 110 |
|
| 111 |
void Structure::set_field(const Glib::ustring& fieldname, const char* value) |
| 112 |
{ |
| 113 |
set_field<std::string>(fieldname, value); |
| 114 |
} |
| 115 |
|
| 116 |
void Structure::remove_field(const Glib::ustring& fieldname) |
| 117 |
{ |
| 118 |
gst_structure_remove_field(gobj(), fieldname.c_str()); |
| 119 |
} |
| 120 |
|
| 121 |
bool Structure::get_field(const Glib::ustring& name, GType enum_type, int& value) const |
| 122 |
{ |
| 123 |
return gst_structure_get_enum(gobj(), name.c_str(), enum_type, &value); |
| 124 |
} |
| 125 |
|
| 126 |
bool Structure::foreach(const SlotForeach& slot) |
| 127 |
{ |
| 128 |
return gst_structure_foreach(gobj(), &Structure_Foreach_gstreamermm_callback, const_cast<SlotForeach*>(&slot)); |
| 129 |
} |
| 130 |
|
| 131 |
bool Structure::map_in_place(const SlotMap& slot) |
| 132 |
{ |
| 133 |
return gst_structure_map_in_place(gobj(), &Structure_Map_gstreamermm_callback, const_cast<SlotMap*>(&slot)); |
| 134 |
} |
| 135 |
|
| 136 |
Structure Structure::create_from_string(const Glib::ustring& the_string) |
| 137 |
{ |
| 138 |
return Structure(gst_structure_from_string(the_string.c_str(), nullptr)); |
| 139 |
} |
| 140 |
|
| 141 |
bool Structure::fixate_nearest_fraction(const Glib::ustring& name, const Gst::Fraction& target) |
| 142 |
{ |
| 143 |
return gst_structure_fixate_field_nearest_fraction(gobj(), name.c_str(), target.num, target.denom); |
| 144 |
} |
| 145 |
|
| 146 |
} //namespace Gst |