[gstreamermm] Structure: Remove the need of conversions when setting fields.
- From: José Alburquerque <jaalburqu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gstreamermm] Structure: Remove the need of conversions when setting fields.
- Date: Tue, 24 May 2011 03:01:57 +0000 (UTC)
commit 048b7db62a0d7902f3ffc1bcd8c957f026ec99f3
Author: José Alburquerque <jaalburqu svn gnome org>
Date: Mon May 23 16:36:05 2011 -0400
Structure: Remove the need of conversions when setting fields.
* gstreamer/src/value.{ccg,hg}: Add Glib::Value<> specializations for
the helper classes so that they can be properly translated by the
Glib::ValueBase system when setting/getting the values to/from the C
API.
* gstreamer/src/structure.{ccg,hg} (_set_gstructure_field): Remove
this method because translation is now done by the Glib::ValueBase
system.
(set_field): Rewritten so it doesn't use the above deleted method.
* gstreamer/src/caps.ccg (set_simple): Also rewritten.
ChangeLog | 14 +++++++
gstreamer/src/caps.ccg | 10 ++---
gstreamer/src/structure.ccg | 79 +--------------------------------------
gstreamer/src/structure.hg | 20 ++++------
gstreamer/src/value.ccg | 86 +++++++++++++++++++++++++++++++++++++++++++
gstreamer/src/value.hg | 72 +++++++++++++++++++++++++++++++++++-
6 files changed, 185 insertions(+), 96 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 962c999..7a93125 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2011-05-23 José Alburquerque <jaalburqu svn gnome org>
+
+ Structure: Remove the need of conversions when setting fields.
+
+ * gstreamer/src/value.{ccg,hg}: Add Glib::Value<> specializations for
+ the helper classes so that they can be properly translated by the
+ Glib::ValueBase system when setting/getting the values to/from the C
+ API.
+ * gstreamer/src/structure.{ccg,hg} (_set_gstructure_field): Remove
+ this method because translation is now done by the Glib::ValueBase
+ system.
+ (set_field): Rewritten so it doesn't use the above deleted method.
+ * gstreamer/src/caps.ccg (set_simple): Also rewritten.
+
2011-05-22 José Alburquerque <jaalburqu svn gnome org>
ElementFactory: Add some new methods.
diff --git a/gstreamer/src/caps.ccg b/gstreamer/src/caps.ccg
index c9c25c7..c1b4e37 100644
--- a/gstreamer/src/caps.ccg
+++ b/gstreamer/src/caps.ccg
@@ -86,14 +86,12 @@ Caps::set_simple(const Glib::ustring& name, const Glib::ValueBase& value)
g_return_if_fail((gobj()->structs->len == 1)); // Not simple
g_return_if_fail (g_atomic_int_get(&(gobj())->refcount) == 1); // IS_WRITABLE(caps) fails
- //Use Gst::Structure so gstremermm GTypes like Gst::Value<Gst::IntRange> are
- //converted to GStreamer types when they are stored in structure
-
- //The result of gst_caps_get_structure() should not be modified, according to its documentation,
- //but we are reimplementing gst_caps_set_simple() which does that:
+ //The result of gst_caps_get_structure() should not be modified, according to
+ //its documentation, but we are reimplementing gst_caps_set_simple() which
+ //does that:
GstStructure* structure = gst_caps_get_structure(gobj(), 0);
if(structure)
- Structure::_set_gstructure_field(structure, name, value);
+ gst_structure_set_value(structure, name.c_str(), value.gobj());
//return Glib::wrap(gobj(), true);
}
diff --git a/gstreamer/src/structure.ccg b/gstreamer/src/structure.ccg
index da8ece8..2a3e204 100644
--- a/gstreamer/src/structure.ccg
+++ b/gstreamer/src/structure.ccg
@@ -95,9 +95,10 @@ void Structure::get_field(const Glib::ustring& name, Glib::ValueBase& value) con
value.init(gst_structure_get_value(gobj(), name.c_str()));
}
-void Structure::set_field(const Glib::ustring& fieldname, const Glib::ValueBase& value)
+void Structure::set_field(const Glib::ustring& fieldname,
+ const Glib::ValueBase& value)
{
- _set_gstructure_field(gobj(), fieldname, value);
+ gst_structure_set_value(gobj(), fieldname.c_str(), value.gobj());
}
void Structure::set_field(const Glib::ustring& fieldname, bool value)
@@ -178,80 +179,6 @@ void Structure::set_field(const Glib::ustring& fieldname, const Gst::FractionRan
value.min.num, value.min.denom, value.max.num, value.max.denom, (void*)0);
}
-
-
-void Structure::_set_gstructure_field(GstStructure* cstructure, const Glib::ustring& fieldname, const Glib::ValueBase& value)
-{
- const GType type = G_VALUE_TYPE(value.gobj());
-
- //The series of if statements below is designed to convert the GTypes of
- //Glib::Value<> enclosing gstreamermm types (such as Gst::Fourcc) to
- //GStreamer GTypes (e.g. a Glib::Value<Gst::Fourcc> is converted to the
- //GST_TYPE_FOURCC GType).
-
- if(type == Glib::Value<Fourcc>::value_type())
- {
- const Glib::Value<Fourcc>* fourcc =
- static_cast< const Glib::Value<Fourcc>* >(&value);
-
- gst_structure_set(cstructure, fieldname.c_str(), GST_TYPE_FOURCC,
- fourcc->get().get_fourcc(), (void*)0);
- }
- else if(type == Glib::Value<IntRange>::value_type())
- {
- const Glib::Value<IntRange>* range =
- static_cast< const Glib::Value<IntRange>* >(&value);
-
- gst_structure_set(cstructure, fieldname.c_str(), GST_TYPE_INT_RANGE,
- range->get().min, range->get().max, (void*)0);
- }
- else if(type == Glib::Value<DoubleRange>::value_type())
- {
- const Glib::Value<DoubleRange>* range =
- static_cast< const Glib::Value<DoubleRange>* >(&value);
-
- gst_structure_set(cstructure, fieldname.c_str(), GST_TYPE_DOUBLE_RANGE,
- range->get().min, range->get().max, (void*)0);
- }
- else if(type == Glib::Value<Fraction>::value_type())
- {
- const Glib::Value<Fraction>* fract =
- static_cast< const Glib::Value<Fraction>* >(&value);
-
- gst_structure_set(cstructure, fieldname.c_str(), GST_TYPE_FRACTION,
- fract->get().num, fract->get().denom, (void*)0);
- }
- else if(type == Glib::Value<FractionRange>::value_type())
- {
- const Glib::Value<FractionRange>* range =
- static_cast< const Glib::Value<FractionRange>* >(&value);
-
- gst_structure_set(cstructure, fieldname.c_str(), GST_TYPE_FRACTION_RANGE,
- range->get().min.num, range->get().min.denom, range->get().max.num,
- range->get().max.denom, (void*)0);
- }
- else if(type == Glib::Value<Glib::Date>::value_type())
- {
- const Glib::Value<Glib::Date>* date =
- static_cast< const Glib::Value<Glib::Date>* >(&value);
-
- gst_structure_set(cstructure, fieldname.c_str(), GST_TYPE_DATE,
- date->get().gobj(), (void*)0);
- }
- else if(type == Glib::Value<Structure>::value_type())
- {
- const Glib::Value<Structure>* obj =
- static_cast< const Glib::Value<Structure>* >(&value);
-
- gst_structure_set(cstructure, fieldname.c_str(), GST_TYPE_STRUCTURE,
- obj->get().gobj(), (void*)0);
- }
- else
- {
- gst_structure_set_value(cstructure, fieldname.c_str(), value.gobj());
- }
-}
-
void Structure::remove_field(const Glib::ustring& fieldname)
{
gst_structure_remove_field(gobj(), fieldname.c_str());
diff --git a/gstreamer/src/structure.hg b/gstreamer/src/structure.hg
index 813ea02..32e821b 100644
--- a/gstreamer/src/structure.hg
+++ b/gstreamer/src/structure.hg
@@ -88,18 +88,17 @@ public:
/** Sets the field with name @a fieldname to value. If the field does not
* exist, it is created. If the field exists, the previous value is replaced
- * and freed. Please note that when setting special GStreamer fields such as
- * Glib::Value<Gst::IntRange> and Glib::Value<Gst::Fraction> and
- * Glib::Value<Glib::Date> they are converted to the GStreamer GTypes and
- * thus when attempting to get these fields back as GValues, they will have
- * the GStreamer GType and can no longer be stored in the same
- * Glib::Value<...>.
+ * and freed.
*
* @param fieldname The name of the field to set.
* @param value The value to set the field to.
*/
void set_field(const Glib::ustring& fieldname, const Glib::ValueBase& value);
- _IGNORE(gst_structure_id_set_value, gst_structure_set_value, gst_structure_id_set_valist, gst_structure_set_valist)
+ _IGNORE(gst_structure_id_set_value,
+ gst_structure_set_value,
+ gst_structure_id_set_valist,
+ gst_structure_set_valist
+ )
/** Sets the field with name @a fieldname to the boolean @a value. If the
* field does not exist, it is created. If the field exists, the previous
@@ -259,11 +258,8 @@ public:
*/
void set_field(const Glib::ustring& fieldname, const Gst::FractionRange& value);
-
-#ifndef DOXYGEN_SHOULD_SKIP_THIS
- //Only for use inside gstreamermm:
- static void _set_gstructure_field(GstStructure* cstructure, const Glib::ustring& fieldname, const Glib::ValueBase& value);
-#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+ // These take ownership of the GValue so they are not wrapped.
+ _IGNORE(gst_structure_take_value, gst_structure_id_take_value)
/** Removes the field with name @a fieldname. If the field with the given
* name does not exist, the structure is unchanged.
diff --git a/gstreamer/src/value.ccg b/gstreamer/src/value.ccg
index 35ce731..1fbf5e3 100644
--- a/gstreamer/src/value.ccg
+++ b/gstreamer/src/value.ccg
@@ -265,3 +265,89 @@ FractionRange::FractionRange(const GValue& value)
}
} //namespace Gst
+
+namespace Glib
+{
+
+// static
+GType Value<Gst::Fourcc>::value_type()
+{
+ return GST_TYPE_FOURCC;
+}
+
+void Value<Gst::Fourcc>::set(const Gst::Fourcc& data)
+{
+ gst_value_set_fourcc(&gobject_, data.get_fourcc());
+}
+
+Gst::Fourcc Value<Gst::Fourcc>::get() const
+{
+ return Gst::Fourcc(gobject_);
+}
+
+// static
+GType Value<Gst::IntRange>::value_type()
+{
+ return GST_TYPE_INT_RANGE;
+}
+
+void Value<Gst::IntRange>::set(const Gst::IntRange& data)
+{
+ gst_value_set_int_range(&gobject_, data.min, data.max);
+}
+
+Gst::IntRange Value<Gst::IntRange>::get() const
+{
+ return Gst::IntRange(gobject_);
+}
+
+// static
+GType Value<Gst::DoubleRange>::value_type()
+{
+ return GST_TYPE_DOUBLE_RANGE;
+}
+
+void Value<Gst::DoubleRange>::set(const Gst::DoubleRange& data)
+{
+ gst_value_set_double_range(&gobject_, data.min, data.max);
+}
+
+Gst::DoubleRange Value<Gst::DoubleRange>::get() const
+{
+ return Gst::DoubleRange(gobject_);
+}
+
+// static
+GType Value<Gst::Fraction>::value_type()
+{
+ return GST_TYPE_FRACTION;
+}
+
+void Value<Gst::Fraction>::set(const Gst::Fraction& data)
+{
+ gst_value_set_fraction(&gobject_, data.num, data.denom);
+}
+
+Gst::Fraction Value<Gst::Fraction>::get() const
+{
+ return Gst::Fraction(gobject_);
+}
+
+// static
+GType Value<Gst::FractionRange>::value_type()
+{
+ return GST_TYPE_FRACTION_RANGE;
+}
+
+void Value<Gst::FractionRange>::set(const Gst::FractionRange& data)
+{
+ gst_value_set_fraction_range_full(&gobject_, data.min.num, data.min.denom,
+ data.max.num, data.max.denom);
+}
+
+Gst::FractionRange Value<Gst::FractionRange>::get() const
+{
+ return Gst::FractionRange(gobject_);
+}
+
+} // namespace Glib
diff --git a/gstreamer/src/value.hg b/gstreamer/src/value.hg
index 9ca0a5b..583410e 100644
--- a/gstreamer/src/value.hg
+++ b/gstreamer/src/value.hg
@@ -80,11 +80,11 @@ public:
/** Construct a Gst::Fourcc from a GST_TYPE_FOURCC.
*/
- explicit Fourcc(const Glib::ValueBase& gst_fraction_value);
+ explicit Fourcc(const Glib::ValueBase& gst_fourcc_value);
/** Construct a Gst::Fourcc from a GST_TYPE_FOURCC.
*/
- explicit Fourcc(const GValue& gst_fraction_value);
+ explicit Fourcc(const GValue& gst_fourcc_value);
Fourcc& operator=(const Fourcc& src);
@@ -325,3 +325,71 @@ public:
};
} //namespace Gst
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+namespace Glib
+{
+
+template<>
+class Value<Gst::Fourcc> : public Value<unsigned int>
+{
+public:
+ typedef Gst::Fourcc CppType;
+ typedef guint32 CType;
+
+ static GType value_type() G_GNUC_CONST;
+
+ void set(const Gst::Fourcc& data);
+ Gst::Fourcc get() const;
+};
+
+template<>
+class Value<Gst::IntRange> : public ValueBase
+{
+public:
+ typedef Gst::IntRange CppType;
+
+ static GType value_type() G_GNUC_CONST;
+
+ void set(const Gst::IntRange& data);
+ Gst::IntRange get() const;
+};
+
+template<>
+class Value<Gst::DoubleRange> : public ValueBase
+{
+public:
+ typedef Gst::DoubleRange CppType;
+
+ static GType value_type() G_GNUC_CONST;
+
+ void set(const Gst::DoubleRange& data);
+ Gst::DoubleRange get() const;
+};
+
+template<>
+class Value<Gst::Fraction> : public ValueBase
+{
+public:
+ typedef Gst::Fraction CppType;
+
+ static GType value_type() G_GNUC_CONST;
+
+ void set(const Gst::Fraction& data);
+ Gst::Fraction get() const;
+};
+
+template<>
+class Value<Gst::FractionRange> : public ValueBase
+{
+public:
+ typedef Gst::FractionRange CppType;
+
+ static GType value_type() G_GNUC_CONST;
+
+ void set(const Gst::FractionRange& data);
+ Gst::FractionRange get() const;
+};
+
+} // namespace Glib
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]