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



Author: jaalburqu
Date: Wed Mar 12 19:43:32 2008
New Revision: 1403
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1403&view=rev

Log:
2008-03-12  Josà Alburquerque  <jaalburqu svn gnome org>

	* gstreamer/src/structure.ccg:
	* gstreamer/src/structure.hg:  Modified get_field() to return the
	GValue from GStreamer as is (without converting to, for example
	Glib::Value<Gst::Fraction>) in case that value is used elsewhere and
	needs to be as GStreamer interprets it; Added comment in set_field()
	docs to explain how setting special GStreamer fields works

	* gstreamer/src/value.ccg:
	* gstreamer/src/value.hg: Added "const ValueBase&" constructors so
	that when GValues are obtained from a Gst::Structure if the GValue
	holds any of these special types they can be easily obtained using
	theese classes.

	* tests/test-structure.cc: Modified test to use "const ValueBase&"
	constructors when getting values from Gst::Structure

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

Modified: gstreamermm/trunk/gstreamer/src/structure.ccg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/structure.ccg	(original)
+++ gstreamermm/trunk/gstreamer/src/structure.ccg	Wed Mar 12 19:43:32 2008
@@ -60,57 +60,7 @@
 void
 Structure::get_field(const Glib::ustring& name, Glib::ValueBase& value) const
 {
-  const GValue* v = gst_structure_get_value(gobj(), name.c_str());
-
-  GType type = G_VALUE_TYPE(v);
-
-  if (type == GST_TYPE_FRACTION)
-  {
-    value.init(Glib::Value<Fraction>::value_type());
-
-    Glib::Value<Fraction>* fract =
-        static_cast< Glib::Value<Fraction>* >(&value);
-
-    fract->set(Fraction(gst_value_get_fraction_numerator(v),
-        gst_value_get_fraction_denominator(v)));
-  }
-  else if (type == GST_TYPE_INT_RANGE)
-  {
-    value.init(Glib::Value<IntRange>::value_type());
-
-    Glib::Value<IntRange>* range =
-        static_cast< Glib::Value<IntRange>* >(&value);
-
-    range->set(IntRange(gst_value_get_int_range_min(v),
-        gst_value_get_int_range_max(v)));
-  }
-  else if (type == GST_TYPE_DOUBLE_RANGE)
-  {
-    value.init(Glib::Value<DoubleRange>::value_type());
-
-    Glib::Value<DoubleRange>* range =
-        static_cast< Glib::Value<DoubleRange>* >(&value);
-
-    range->set(DoubleRange(gst_value_get_double_range_min(v),
-        gst_value_get_double_range_max(v)));
-  }
-  else if (type == GST_TYPE_FRACTION_RANGE)
-  {
-    const GValue* min = gst_value_get_fraction_range_min(v);
-    const GValue* max = gst_value_get_fraction_range_max(v);
-
-    value.init(Glib::Value<FractionRange>::value_type());
-
-    Glib::Value<FractionRange>* range =
-        static_cast< Glib::Value<FractionRange>* >(&value);
-
-    range->set(FractionRange(Fraction(gst_value_get_fraction_numerator(min),
-        gst_value_get_fraction_denominator(min)),
-            Fraction(gst_value_get_fraction_numerator(max),
-                gst_value_get_fraction_denominator(max))));
-  }
-  else
-    value.init(v);
+  value.init(gst_structure_get_value(gobj(), name.c_str()));
 }
 
 Structure&

Modified: gstreamermm/trunk/gstreamer/src/structure.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/structure.hg	(original)
+++ gstreamermm/trunk/gstreamer/src/structure.hg	Wed Mar 12 19:43:32 2008
@@ -75,6 +75,11 @@
   /** Sets the field with the given name field to value. If the field does not
    * exist, it is created. If the field exists, the previous value is replaced
    * and freed. Returns this Structure for continued setting convenience.
+   * Please note that when setting special GStreamer fields such as
+   * Glib::Value<Gst::IntRange> and Glib::Value<Gst::Fraction> (using classes
+   * in value.h) they are converted to the GStreamer GTypes and thus when
+   * attempting to get these fields back, they can no longer be stored in the
+   * same Glib::Value<...>.
    *
    * @param fieldname the name of the field to set
    * @param value the new value of the field 

Modified: gstreamermm/trunk/gstreamer/src/value.ccg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/value.ccg	(original)
+++ gstreamermm/trunk/gstreamer/src/value.ccg	Wed Mar 12 19:43:32 2008
@@ -31,6 +31,15 @@
 Fraction::Fraction(const Fraction& f) : num(f.num), denom(f.denom)
 {}
 
+Fraction::Fraction(const Glib::ValueBase& value) : num(0), denom(1)
+{
+  if(G_VALUE_TYPE(value.gobj()) == GST_TYPE_FRACTION)
+  {
+    num = gst_value_get_fraction_numerator(value.gobj());
+    denom = gst_value_get_fraction_denominator(value.gobj());
+  }
+}
+
 IntRange::IntRange() : min(0), max(0)
 {}
 
@@ -40,6 +49,15 @@
 IntRange::IntRange(const IntRange& r) : min(r.min), max(r.max)
 {}
 
+IntRange::IntRange(const Glib::ValueBase& value) : min(0), max(0)
+{
+  if(G_VALUE_TYPE(value.gobj()) == GST_TYPE_INT_RANGE)
+  {
+    min = gst_value_get_int_range_min(value.gobj());
+    max = gst_value_get_int_range_max(value.gobj());
+  }
+}
+
 DoubleRange::DoubleRange() : min(0), max(0)
 {}
 
@@ -49,6 +67,15 @@
 DoubleRange::DoubleRange(const DoubleRange& r) : min(r.min), max(r.max)
 {}
 
+DoubleRange::DoubleRange(const Glib::ValueBase& value) : min(0), max(0)
+{
+  if(G_VALUE_TYPE(value.gobj()) == GST_TYPE_DOUBLE_RANGE)
+  {
+    min = gst_value_get_double_range_min(value.gobj());
+    max = gst_value_get_double_range_max(value.gobj());
+  }
+}
+
 FractionRange::FractionRange() : min(), max()
 {}
 
@@ -58,5 +85,20 @@
 FractionRange::FractionRange(const FractionRange& r) : min(r.min), max(r.max)
 {}
 
+FractionRange::FractionRange(const Glib::ValueBase& value) : min(), max()
+{
+  if(G_VALUE_TYPE(value.gobj()) == GST_TYPE_FRACTION_RANGE)
+  {
+    const GValue* min = gst_value_get_fraction_range_min(value.gobj());
+    const GValue* max = gst_value_get_fraction_range_max(value.gobj());
+
+    this->min.num = gst_value_get_fraction_numerator(min);
+    this->min.denom = gst_value_get_fraction_denominator(min);
+
+    this->max.num = gst_value_get_fraction_numerator(max);
+    this->max.denom = gst_value_get_fraction_denominator(max);
+  }
+}
+
 } //namespace Gst
 

Modified: gstreamermm/trunk/gstreamer/src/value.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/value.hg	(original)
+++ gstreamermm/trunk/gstreamer/src/value.hg	Wed Mar 12 19:43:32 2008
@@ -29,19 +29,23 @@
 
 /** Represents a fraction for use to store in Structures of Caps as a value
  * representing a property (see GStreamer Application Development Manual
- * section 8.2.2 for explanation).  The class can be used in setting and
- * getting a Structure's field like so:
+ * section 8.2.2 for explanation).  When the value is set, it is transformed to
+ * a GStreamer GType so retrieving the value is a bit different.  The class can
+ * be used in setting and getting a Structure's field like so:
  *
  * @code
- * Glib::Value<Gst::Fraction> fract_value;
- * fract_value.init(Glib::Value<Gst::Fraction>::value_type());
- * fract_value.set(Gst::Fraction(25,1));
+ * Glib::Value<Gst::Fraction> value;
+ * value.init(Glib::Value<Gst::Fraction>::value_type());
+ * value.set(Gst::Fraction(25,1));
  *
  * Gst::Structure structure("my-structure");
- * structure.set_field("framerate", fract_value);
+ * structure.set_field("framerate", value);
+ * ...
+ * Glib::ValueBase gst_value;
+ * structure.get_field("framerate", gst_value);
+ * Gst::Fraction fract(gst_value);
+ * int numerator = fract.num;
  * ...
- * Glib::Value<Gst::Fraction> fract_copy;
- * structure.get_field("framerate", fract_copy);
  * @code
  */
 class Fraction
@@ -50,27 +54,33 @@
   Fraction();
   Fraction(int num, int denom);
   Fraction(const Fraction& f);
+  Fraction(const Glib::ValueBase& gst_fraction_value);
 public:
   int num;
   int denom;
 };
 
 
-/** Represents a integer range (min - max) for use to store in Structures of
+/** Represents an integer range (min - max) for use to store in Structures of
  * Caps as a value representing a property (see GStreamer Application
- * Development Manual section 8.2.2 for explanation).  The class can be used in
- * setting and getting a Structure's field like so:
+ * Development Manual section 8.2.2 for explanation).  When the value is set,
+ * it is transformed to a GStreamer GType so retrieving the value is a bit
+ * different.  The class can be used in setting and getting a Structure's field
+ * like so:
  *
  * @code
- * Glib::Value<Gst::IntRange> range;
- * range.init(Glib::Value<Gst::IntRange>::value_type());
- * range.set(Gst::IntRange(8000, 50000));
+ * Glib::Value<Gst::IntRange> value;
+ * value.init(Glib::Value<Gst::IntRange>::value_type());
+ * value.set(Gst::IntRange(8000, 50000));
  *
  * Gst::Structure structure("my-structure");
- * structure.set_field("rate", range);
+ * structure.set_field("rate", value);
+ * ...
+ * Glib::ValueBase gst_value;
+ * structure.get_field("rate", gst_value);
+ * Gst::IntRange range(gst_value);
+ * int max = range.max;
  * ...
- * Glib::Value<Gst::IntRange> range_copy;
- * structure.get_field("rate", range_copy);
  * @code
  */
 class IntRange
@@ -79,26 +89,32 @@
   IntRange();
   IntRange(int min, int max);
   IntRange(const IntRange& r);
+  IntRange(const Glib::ValueBase& gst_int_range_value);
 public:
   int min;
   int max;
 };
 
-/** Represents a floating (double) range (min - max) for use to store in
- * Structures of Caps as a value representing a property (see GStreamer
- * Application Development Manual section 8.2.2 for explanation).  The class
- * can be used in setting and getting a Structure's field like so:
+/** Represents a double range (min - max) for use to store in Structures of
+ * Caps as a value representing a property (see GStreamer Application
+ * Development Manual section 8.2.2 for explanation).  When the value is set,
+ * it is transformed to a GStreamer GType so retrieving the value is a bit
+ * different.  The class can be used in setting and getting a Structure's field
+ * like so:
  *
  * @code
- * Glib::Value<Gst::DoubleRange> range;
- * range.init(Glib::Value<Gst::DoubleRange>::value_type());
- * range.set(Gst::DoubleRange(44.1, 48.0));
+ * Glib::Value<Gst::DoubleRange> value;
+ * value.init(Glib::Value<Gst::DoubleRange>::value_type());
+ * value.set(Gst::DoubleRange(44.1, 48.0));
  *
  * Gst::Structure structure("my-structure");
- * structure.set_field("rate", range);
+ * structure.set_field("rate", value);
+ * ...
+ * Glib::ValueBase gst_value;
+ * structure.get_field("rate", gst_value);
+ * Gst::DoubleRange range(gst_value);
+ * double min = range.min;
  * ...
- * Glib::Value<Gst::DoubleRange> range_copy;
- * structure.get_field("rate", range_copy);
  * @code
  */
 class DoubleRange
@@ -107,6 +123,7 @@
   DoubleRange();
   DoubleRange(double min, double max);
   DoubleRange(const DoubleRange& r);
+  DoubleRange(const Glib::ValueBase& gst_double_range_value);
 public:
   double min;
   double max;
@@ -115,19 +132,23 @@
 
 /** Represents a fractional range for use to store in Structures of Caps as a
  * value representing a property (see GStreamer Application Development Manual
- * section 8.2.2 for explanation).  The class can be used in setting and
- * getting a Structure's field like so:
+ * section 8.2.2 for explanation).  When the value is set, it is transformed to
+ * a GStreamer GType so retrieving the value is a bit different.  The class can
+ * be used in setting and getting a Structure's field like so:
  *
  * @code
- * Glib::Value<Gst::FractionRange> range;
- * range.init(Glib::Value<Gst::Fraction>::value_type());
- * range.set(Gst::FractionRange(Gst::Fraction(1,2), Gst::Fraction(3,4));
+ * Glib::Value<Gst::FractionRange> value;
+ * value.init(Glib::Value<Gst::Fraction>::value_type());
+ * value.set(Gst::FractionRange(Gst::Fraction(1,2), Gst::Fraction(3,4)));
  *
  * Gst::Structure structure("my-structure");
- * structure.set_field("range", range);
+ * structure.set_field("range", value);
+ * ...
+ * Glib::ValueBase gst_value;
+ * structure.get_field("rate", gst_value);
+ * Gst::FractionRange range(gst_value);
+ * int min_numerator = range.min.num;
  * ...
- * Glib::Value<Gst::FractionRange> range_copy;
- * structure.get_field("range", range_copy);
  * @code
  */
 class FractionRange
@@ -136,6 +157,7 @@
   FractionRange();
   FractionRange(const Fraction& min, const Fraction& max);
   FractionRange(const FractionRange& r);
+  FractionRange(const Glib::ValueBase& gst_fraction_range_value);
 public:
   Fraction min;
   Fraction max;

Modified: gstreamermm/trunk/tests/test-structure.cc
==============================================================================
--- gstreamermm/trunk/tests/test-structure.cc	(original)
+++ gstreamermm/trunk/tests/test-structure.cc	Wed Mar 12 19:43:32 2008
@@ -54,16 +54,18 @@
   structure.get_field("integer", value2);
   std::cout << "integer value = '" << value2.get() << "'" << std::endl;
 
-  Glib::Value<Gst::Fraction> value3;
+  Glib::ValueBase value3;
   structure.get_field("fraction", value3);
-  std::cout << "fraction value = '" << value3.get().num << "/" <<
-      value3.get().denom << "'" << std::endl;
+  Gst::Fraction fract(value3);
+  std::cout << "fraction value = '" << fract.num << "/" <<
+      fract.denom << "'" << std::endl;
 
-  Glib::Value<Gst::FractionRange> value4;
+  Glib::ValueBase value4;
   structure.get_field("range", value4);
-  std::cout << "fractional range value = '[(" << value4.get().min.num << "/" <<
-      value4.get().min.denom << "), (" << value4.get().max.num << "/" <<
-          value4.get().max.denom << ")]'" << std::endl;
+  Gst::FractionRange range(value4);
+  std::cout << "fractional range value = '[(" << range.min.num << "/" <<
+      range.min.denom << "), (" << range.max.num << "/" << range.max.denom <<
+          ")]'" << std::endl;
 
   return 0;
 }



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