gnomemm r1548 - in gstreamermm/trunk: . gstreamer/src tests



Author: jaalburqu
Date: Tue Jun  3 00:35:53 2008
New Revision: 1548
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1548&view=rev

Log:
2008-06-02  Josà Alburquerque  <jaalburqu svn gnome org>

	* gstreamer/src/structure.ccg:
	* gstreamer/src/structure.hg: Added {get,set}_field() methods for
	Gst::{Int,Double}Range types. Modified set_field() methods to use
	gst_structure_set() to set the given values.
	* tests/test-caps-structures.cc: Modified test to use regular types
	instead of Glib::Value<>.

Modified:
   gstreamermm/trunk/ChangeLog
   gstreamermm/trunk/gstreamer/src/structure.ccg
   gstreamermm/trunk/gstreamer/src/structure.hg
   gstreamermm/trunk/tests/test-caps-structures.cc

Modified: gstreamermm/trunk/gstreamer/src/structure.ccg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/structure.ccg	(original)
+++ gstreamermm/trunk/gstreamer/src/structure.ccg	Tue Jun  3 00:35:53 2008
@@ -75,91 +75,51 @@
 
 void Structure::set_field(const Glib::ustring& fieldname, bool value)
 {
-   Glib::Value<bool> val;
-   val.init( Glib::Value<bool>::value_type() );
-   val.set(value);
-
-   set_field(fieldname, val);
+  gst_structure_set(gobj(), fieldname.c_str(), G_TYPE_BOOLEAN, value, NULL);
 }
 
 void Structure::set_field(const Glib::ustring& fieldname, int value)
 {
-  Glib::Value<int> val;
-  val.init( Glib::Value<int>::value_type() );
-  val.set(value);
-
-  set_field(fieldname, val);
+  gst_structure_set(gobj(), fieldname.c_str(), G_TYPE_INT, value, NULL);
 }
 
 void Structure::set_field(const Glib::ustring& fieldname, guint value)
 {
-  Glib::Value<guint> val;
-  val.init( Glib::Value<guint>::value_type() );
-  val.set(value);
-
-  set_field(fieldname, val);
+  gst_structure_set(gobj(), fieldname.c_str(), G_TYPE_UINT, value, NULL);
 }
 
 void Structure::set_field(const Glib::ustring& fieldname, const Fourcc& value)
 {
-  //Using a Fourcc is fine because _set_gstructure_field() makes appropriate
-  //conversion to GStreamer GType
-  Glib::Value<Fourcc> val;
-  val.init( Glib::Value<Fourcc>::value_type() );
-  val.set(value);
-
-  set_field(fieldname, val);
+  gst_structure_set(gobj(), fieldname.c_str(), GST_TYPE_FOURCC,
+    value.get_fourcc(), NULL);
 }
 
 void Structure::set_field(const Glib::ustring& fieldname, double value)
 {
-  Glib::Value<double> val;
-  val.init( Glib::Value<double>::value_type() );
-  val.set(value);
-
-  set_field(fieldname, val);
+  gst_structure_set(gobj(), fieldname.c_str(), G_TYPE_DOUBLE, value, NULL);
 };
 
 //We use std::string, because the encoding is unknown. murrayc
 void Structure::set_field(const Glib::ustring& fieldname, const std::string& value)
 {
-  Glib::Value<std::string> val;
-  val.init( Glib::Value<std::string>::value_type() );
-  val.set(value);
-
-  set_field(fieldname, val);
+  gst_structure_set(gobj(), fieldname.c_str(), G_TYPE_STRING, value.c_str(), NULL);
 }
 
 //We use std::string, because the encoding is unknown. murrayc
 void Structure::set_field(const Glib::ustring& fieldname, const char* value)
 {
-  Glib::Value<std::string> val;
-  val.init( Glib::Value<std::string>::value_type() );
-  val.set(value);
-
-  set_field(fieldname, val);
+  gst_structure_set(gobj(), fieldname.c_str(), G_TYPE_STRING, value, NULL);
 }
  
 void Structure::set_field(const Glib::ustring& fieldname, const Glib::Date& value)
 {
-  //Using a Glib::Date is fine because _set_gstructure_field() makes
-  //appropriate conversion to GStreamer GType
-  Glib::Value<Glib::Date> val;
-  val.init( Glib::Value<Glib::Date>::value_type() );
-  val.set(value);
-
-  set_field(fieldname, val);
+  gst_structure_set(gobj(), fieldname.c_str(), GST_TYPE_DATE, value.gobj(), NULL);
 }
 
 void Structure::set_field(const Glib::ustring& fieldname, const ClockTime& value)
 {
-  //Using a ClockTime is fine because a ClockTime is a GstClockTime which is a
-  //guint64 which GStreamer will interpret correctly
-  Glib::Value<ClockTime> val;
-  val.init( Glib::Value<ClockTime>::value_type() );
-  val.set(value);
-
-  set_field(fieldname, val);
+  gst_structure_set(gobj(), fieldname.c_str(), GST_TYPE_CLOCK_TIME,
+    (GstClockTime) value, NULL);
 }
 
 void Structure::set_field(const Glib::ustring& fieldname, GType enumtype, int value)
@@ -169,24 +129,26 @@
 
 void Structure::set_field(const Glib::ustring& fieldname, const Gst::Fraction& value)
 {
-  //Using a Gst::Fraction is fine because _set_gstructure_field() makes
-  //appropriate conversion to GStreamer GType
-  Glib::Value<Gst::Fraction> val;
-  val.init( Glib::Value<Gst::Fraction>::value_type() );
-  val.set(value);
+  gst_structure_set(gobj(), fieldname.c_str(), GST_TYPE_FRACTION, value.num,
+    value.denom, NULL);
+}
+
+void Structure::set_field(const Glib::ustring& fieldname, const Gst::IntRange& value)
+{
+  gst_structure_set(gobj(), fieldname.c_str(), GST_TYPE_INT_RANGE, value.min,
+    value.max, NULL);
+}
 
-   set_field(fieldname, val);
+void Structure::set_field(const Glib::ustring& fieldname, const Gst::DoubleRange& value)
+{
+  gst_structure_set(gobj(), fieldname.c_str(), GST_TYPE_DOUBLE_RANGE,
+    value.min, value.max, NULL);
 }
 
 void Structure::set_field(const Glib::ustring& fieldname, const Gst::FractionRange& value)
 {
-  //Using a Gst::FractionRange is fine because _set_gstructure_field() makes
-  //appropriate conversion to GStreamer GType
-  Glib::Value<Gst::FractionRange> val;
-  val.init( Glib::Value<Gst::FractionRange>::value_type() );
-  val.set(value);
-
-  set_field(fieldname, val);
+  gst_structure_set(gobj(), fieldname.c_str(), GST_TYPE_FRACTION_RANGE,
+    value.min.num, value.min.denom, value.max.num, value.max.denom, NULL);
 }
 
 
@@ -195,6 +157,11 @@
 {
   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 =
@@ -262,7 +229,6 @@
   }
   else
   {
-    //TODO: Why not just use this instead of all the if/else stuff above? murrayc
     gst_structure_set_value(cstructure, fieldname.c_str(), value.gobj());
   }
 }
@@ -381,15 +347,55 @@
 }
 
 bool
+Structure::get_field(const Glib::ustring& name, Gst::IntRange& range) const
+{
+  const GValue* gst_range_val = gst_structure_get_value(gobj(), name.c_str());
+
+  if (G_VALUE_TYPE(gst_range_val) == GST_TYPE_INT_RANGE)
+  {
+    const gint min = gst_value_get_int_range_min(gst_range_val);
+    const gint max = gst_value_get_int_range_max(gst_range_val);
+    range = Gst::IntRange(min, max);
+    return true;
+  }
+
+  return false;
+}
+
+bool
+Structure::get_field(const Glib::ustring& name, Gst::DoubleRange& range) const
+{
+  const GValue* gst_range_val = gst_structure_get_value(gobj(), name.c_str());
+
+  if (G_VALUE_TYPE(gst_range_val) == GST_TYPE_DOUBLE_RANGE)
+  {
+    const gdouble min = gst_value_get_double_range_min(gst_range_val);
+    const gdouble max = gst_value_get_double_range_max(gst_range_val);
+    range = Gst::DoubleRange(min, max);
+    return true;
+  }
+
+  return false;
+}
+
+bool
 Structure::get_field(const Glib::ustring& name, Gst::FractionRange& range) const
 {
-  const GValue* gst_fraction_range_val = gst_structure_get_value(gobj(), name.c_str());
+  const GValue* gst_range_val = gst_structure_get_value(gobj(), name.c_str());
 
-  if (gst_structure_get_field_type(gobj(), name.c_str()) == GST_TYPE_FRACTION_RANGE)
+  if (G_VALUE_TYPE(gst_range_val) == GST_TYPE_FRACTION_RANGE)
   {
-    Glib::ValueBase fraction_range_val;
-    fraction_range_val.init(gst_fraction_range_val);
-    range = Gst::FractionRange(fraction_range_val);
+    const GValue* gst_min_val = gst_value_get_fraction_range_min(gst_range_val);
+    const gint min_num = gst_value_get_fraction_numerator(gst_min_val);
+    const gint min_denom = gst_value_get_fraction_denominator(gst_min_val);
+
+    const GValue* gst_max_val = gst_value_get_fraction_range_max(gst_range_val);
+    const gint max_num = gst_value_get_fraction_numerator(gst_max_val);
+    const gint max_denom = gst_value_get_fraction_denominator(gst_max_val);
+
+    range = Gst::FractionRange(Gst::Fraction(min_num, max_num),
+      Gst::Fraction(max_num, max_denom));
+
     return true;
   }
 

Modified: gstreamermm/trunk/gstreamer/src/structure.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/structure.hg	(original)
+++ gstreamermm/trunk/gstreamer/src/structure.hg	Tue Jun  3 00:35:53 2008
@@ -210,6 +210,32 @@
    */
   void set_field(const Glib::ustring& fieldname, const Gst::Fraction& value);
 
+  /** Sets the field with name @a fieldname field to the Gst::IntRange @a
+   * 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
+   * fields to special types such as Gst::Fourcc and Gst::Fraction and
+   * 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.
+   *
+   * @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 Gst::IntRange& value);
+
+  /** Sets the field with name @a fieldname field to the Gst::DoubleRange @a
+   * 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
+   * fields to special types such as Gst::Fourcc and Gst::Fraction and
+   * 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.
+   *
+   * @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 Gst::DoubleRange& value);
+
   /** Sets the field with name @a fieldname field to the Gst::FractionRange @a
    * 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
@@ -406,27 +432,49 @@
    * correct type.
    *
    * @param fieldname The name of a field.
-   * @param fraction The Gst::Fraction to set.
+   * @param value The Gst::Fraction to set.
    * @return true if @a value could be set correctly. If there was no field
    * with @a fieldname or the existing field did not contain a Gst::Fraction,
    * this function returns false.
    */
-  bool get_field(const Glib::ustring& fieldname, Gst::Fraction& fraction) const;
+  bool get_field(const Glib::ustring& fieldname, Gst::Fraction& value) const;
   _IGNORE(gst_structure_get_fraction)
 
+  /** Gets the value of field @a fieldname into Gst::IntRange @a value.
+   * The caller is responsible for making sure the field exists and has the
+   * correct type.
+   *
+   * @param fieldname The name of a field.
+   * @param value The Gst::IntRange to set.
+   * @return true if @a value could be set correctly. If there was no field
+   * with @a fieldname or the existing field did not contain a Gst::IntRange,
+   * this function returns false.
+   */
+  bool get_field(const Glib::ustring& fieldname, Gst::IntRange& value) const;
+
+  /** Gets the value of field @a fieldname into Gst::DoubleRange @a value.
+   * The caller is responsible for making sure the field exists and has the
+   * correct type.
+   *
+   * @param fieldname The name of a field.
+   * @param value The Gst::DoubleRange to set.
+   * @return true if @a value could be set correctly. If there was no field
+   * with @a fieldname or the existing field did not contain a
+   * Gst::DoubleRange, this function returns false.
+   */
+  bool get_field(const Glib::ustring& fieldname, Gst::DoubleRange& value) const;
+
   /** Gets the value of field @a fieldname into Gst::FractionRange @a value.
    * The caller is responsible for making sure the field exists and has the
    * correct type.
    *
    * @param fieldname The name of a field.
-   * @param fraction The Gst::FractionRange to set.
+   * @param value The Gst::FractionRange to set.
    * @return true if @a value could be set correctly. If there was no field
    * with @a fieldname or the existing field did not contain a
    * Gst::FractionRange, this function returns false.
    */
-  bool get_field(const Glib::ustring& fieldname, Gst::FractionRange& fraction) const;
-
-  //TODO: Add Set/Get for the other *Range classes?
+  bool get_field(const Glib::ustring& fieldname, Gst::FractionRange& value) const;
 
   /** For example,
    * bool on_map(const Glib::QueryQuark& id, Glib::ValueBase& value);

Modified: gstreamermm/trunk/tests/test-caps-structures.cc
==============================================================================
--- gstreamermm/trunk/tests/test-caps-structures.cc	(original)
+++ gstreamermm/trunk/tests/test-caps-structures.cc	Tue Jun  3 00:35:53 2008
@@ -28,16 +28,13 @@
   Gst::Structure struct2("Structure 2");
   Gst::Structure struct3("Structure 3");
 
-  Glib::Value<Glib::ustring> message;
-  message.init(Glib::Value<Glib::ustring>::value_type());
-
-  message.set("Message 1");
+  Glib::ustring message = "Message 1";
   struct1.set_field("message", message);
 
-  message.set("Message 2");
+  message = "Message 2";
   struct2.set_field("message", message);
 
-  message.set("Message 3");
+  message = "Message 3";
   struct3.set_field("message", message);
 
   caps->append_structure(struct1);
@@ -53,12 +50,12 @@
   add_structures(caps);
 
   for (int i = 0; i < 2; i++) {
-    Glib::Value<Glib::ustring> v;
+    Glib::ustring str;
     const Gst::Structure s = caps->get_structure(i);
     if(s)
     {
-      s.get_field("message", v);
-      std::cout << s.get_name() << ": " << v.get() << std::endl;
+      s.get_field("message", str);
+      std::cout << s.get_name() << ": " << str << std::endl;
     }
   }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]