gnomemm r1412 - in gstreamermm/trunk: . gstreamer/gstreamermm gstreamer/src tests tools/m4
- From: jaalburqu svn gnome org
- To: svn-commits-list gnome org
- Subject: gnomemm r1412 - in gstreamermm/trunk: . gstreamer/gstreamermm gstreamer/src tests tools/m4
- Date: Wed, 19 Mar 2008 22:41:43 +0000 (GMT)
Author: jaalburqu
Date: Wed Mar 19 22:41:43 2008
New Revision: 1412
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1412&view=rev
Log:
2008-03-19 Josà Alburquerque <jaalburqu svn gnome org>
* gstreamer/src/value.ccg:
* gstreamer/src/value.hg: Added Fourcc class; Added constructor docs;
Refined previous docs to reference GstValue for better understanding
of classes in value.hg
* gstreamer/src/structure.ccg:
* gstreamer/src/structure.hg: Modified get_fraction() to take a
Gst::Fraction& in which to set values; Fixed docs for get_date() and
get_fraction(); Added conversion lines in set_field() for Glib::Value<Gst::Fourcc>, Glib::Value<Glib::Date>, Glib::Value<Structure> and Glib::Value<MiniObject>
* gstreamer/gstreamermm/miniobject.cc:
* gstreamer/gstreamermm/miniobject.h: Added take_copy param to
MiniObject(GstMiniObject*, bool); Added definitions swap(),
operator=() and MiniObject(const MiniObject&) (the copy constructor is
needed if it is embedded in a Glib::Value<...>)
* tests/test-structure.cc: Modified to test setting and getting a
Glib::Date field (embedded in a Glib::Value<...>)
* tools/m4/class_boxedtype_ncopy.m4: Added comment on destruction of
underlying gobject
Modified:
gstreamermm/trunk/ChangeLog
gstreamermm/trunk/gstreamer/gstreamermm/miniobject.cc
gstreamermm/trunk/gstreamer/gstreamermm/miniobject.h
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
gstreamermm/trunk/tools/m4/class_boxedtype_ncopy.m4
Modified: gstreamermm/trunk/gstreamer/gstreamermm/miniobject.cc
==============================================================================
--- gstreamermm/trunk/gstreamer/gstreamermm/miniobject.cc (original)
+++ gstreamermm/trunk/gstreamer/gstreamermm/miniobject.cc Wed Mar 19 22:41:43 2008
@@ -32,17 +32,37 @@
{
}
-MiniObject::MiniObject(GstMiniObject* castitem)
-: gobject_(castitem)
+MiniObject::MiniObject(GstMiniObject* castitem, bool take_copy)
+: gobject_(take_copy ? gst_mini_object_copy(castitem) : castitem)
{
}
+MiniObject::MiniObject(const MiniObject& other)
+: gobject_(gst_mini_object_copy(other.gobject_))
+{
+}
+
+MiniObject&
+MiniObject::operator=(const MiniObject& other)
+{
+ MiniObject temp(other);
+ swap(temp);
+ return *this;
+}
+
MiniObject::~MiniObject()
{
if(gobject_)
gst_mini_object_unref(gobject_);
}
+void MiniObject::swap(MiniObject& other)
+{
+ GstMiniObject *const temp = gobject_;
+ gobject_ = other.gobject_;
+ other.gobject_ = temp;
+}
+
void
MiniObject::reference() const
{
@@ -56,6 +76,13 @@
}
// TODO: Investigate how this works:
+
+// TODO: As far as I can tell, derived types must implement a
+// TODO: GstMiniObjectCopyFunction in a class structure.
+// TODO: gst_mini_object_class_init() sets the (*GstMiniObjectCopyFunction)(...)
+// TODO: to gst_mini_object_copy_default() which does nothing, but derived
+// TODO: types (like GstQuery, etc) have their own functions (like
+// TODO: gst_query_copy()) which do work. Jose
/*
Glib::RefPtr<Gst::MiniObject>
MiniObject::copy()
Modified: gstreamermm/trunk/gstreamer/gstreamermm/miniobject.h
==============================================================================
--- gstreamermm/trunk/gstreamer/gstreamermm/miniobject.h (original)
+++ gstreamermm/trunk/gstreamer/gstreamermm/miniobject.h Wed Mar 19 22:41:43 2008
@@ -30,7 +30,6 @@
/** This is a base class for some gstreamermm objects.
* It is similar to Glib::Object but has no GObject property or signal support.
- * Use Gst::wrap() (instead of Glib::wrap()) to create C++ instances that wrap C instances.
*/
class MiniObject : public Glib::ObjectBase
{
@@ -47,7 +46,7 @@
//friend Glib::wrap;
MiniObject();
- MiniObject(GstMiniObject* castitem);
+ MiniObject(GstMiniObject* castitem, bool take_copy = false);
public:
virtual ~MiniObject();
@@ -56,7 +55,6 @@
//because it's just an equivalent for g_object_new(),
//which is just an equivalent for C++'s new().
-
//private:
// noncopyable
MiniObject(const MiniObject&);
@@ -81,6 +79,9 @@
// static void replace(Glib::RefPtr<Gst::MiniObject> & olddata, Glib::RefPtr<Gst::MiniObject> & newdata);
protected:
+ void swap(MiniObject& other);
+
+protected:
GstMiniObject* gobject_; //TODO: Doesn't this shadow a member variable in Glib::ObjectBase?
};
Modified: gstreamermm/trunk/gstreamer/src/structure.ccg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/structure.ccg (original)
+++ gstreamermm/trunk/gstreamer/src/structure.ccg Wed Mar 19 22:41:43 2008
@@ -22,6 +22,7 @@
#include <gst/gstvalue.h> //Must be included before gststructure.h
#include <gst/gststructure.h>
#include <gstreamermm/value.h>
+#include <gstreamermm/miniobject.h>
static gboolean
Structure_Foreach_gstreamermm_callback(GQuark field_id, const GValue *value, void* data)
@@ -68,13 +69,13 @@
{
GType type = G_VALUE_TYPE(value.gobj());
- if (type == Glib::Value<Fraction>::value_type())
+ if (type == Glib::Value<Fourcc>::value_type())
{
- const Glib::Value<Fraction>* fract =
- static_cast< const Glib::Value<Fraction>* >(&value);
+ const Glib::Value<Fourcc>* fourcc =
+ static_cast< const Glib::Value<Fourcc>* >(&value);
- gst_structure_set(gobj(), fieldname.c_str(), GST_TYPE_FRACTION,
- fract->get().num, fract->get().denom, NULL);
+ gst_structure_set(gobj(), fieldname.c_str(), GST_TYPE_FOURCC,
+ fourcc->get().get_fourcc(), NULL);
}
else if (type == Glib::Value<IntRange>::value_type())
{
@@ -92,6 +93,14 @@
gst_structure_set(gobj(), fieldname.c_str(), GST_TYPE_DOUBLE_RANGE,
range->get().min, range->get().max, NULL);
}
+ else if (type == Glib::Value<Fraction>::value_type())
+ {
+ const Glib::Value<Fraction>* fract =
+ static_cast< const Glib::Value<Fraction>* >(&value);
+
+ gst_structure_set(gobj(), fieldname.c_str(), GST_TYPE_FRACTION,
+ fract->get().num, fract->get().denom, NULL);
+ }
else if (type == Glib::Value<FractionRange>::value_type())
{
const Glib::Value<FractionRange>* range =
@@ -101,6 +110,30 @@
range->get().min.num, range->get().min.denom, range->get().max.num,
range->get().max.denom, NULL);
}
+ 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(gobj(), fieldname.c_str(), GST_TYPE_DATE,
+ date->get().gobj(), NULL);
+ }
+ else if (type == Glib::Value<Structure>::value_type())
+ {
+ const Glib::Value<Structure>* obj =
+ static_cast< const Glib::Value<Structure>* >(&value);
+
+ gst_structure_set(gobj(), fieldname.c_str(), GST_TYPE_STRUCTURE,
+ obj->get().gobj(), NULL);
+ }
+ else if (type == Glib::Value<MiniObject>::value_type())
+ {
+ const Glib::Value<MiniObject>* obj =
+ static_cast< const Glib::Value<MiniObject>* >(&value);
+
+ gst_structure_set(gobj(), fieldname.c_str(), GST_TYPE_MINI_OBJECT,
+ obj->get().gobj(), NULL);
+ }
else
gst_structure_set_value(gobj(), fieldname.c_str(), value.gobj());
@@ -182,11 +215,11 @@
}
bool
-Structure::get_date (const Glib::ustring& name, Glib::Date& value) const
+Structure::get_date (const Glib::ustring& name, Glib::Date& date) const
{
- GDate *date = 0;
- const bool has = gst_structure_get_date(gobj(), name.c_str(), &date);
- value.set_julian(g_date_get_julian(date));
+ GDate *gdate = 0;
+ const bool has = gst_structure_get_date(gobj(), name.c_str(), &gdate);
+ date.set_julian(g_date_get_julian(gdate));
return has;
}
@@ -216,9 +249,9 @@
bool
-Structure::get_fraction(const Glib::ustring& name, int& value_numerator, int& value_denominator) const
+Structure::get_fraction(const Glib::ustring& name, Gst::Fraction& f) const
{
- return gst_structure_get_fraction(gobj(), name.c_str(), &value_numerator, &value_denominator);
+ return gst_structure_get_fraction(gobj(), name.c_str(), &f.num, &f.denom);
}
bool
Modified: gstreamermm/trunk/gstreamer/src/structure.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/structure.hg (original)
+++ gstreamermm/trunk/gstreamer/src/structure.hg Wed Mar 19 22:41:43 2008
@@ -21,6 +21,7 @@
#include <gstreamermm/clock.h>
#include <gstreamermm/enums.h>
+#include <gstreamermm/value.h>
_DEFS(gstreamermm,gst)
@@ -175,7 +176,7 @@
* is responsible for making sure the field exists and has the correct type.
*
* @param fieldname the name of a field
- * @param value the Value class to set
+ * @param date the Glib::Date class to set
* @return TRUE if the value could be set correctly. If there was no field
* with fieldname or the existing field did not contain a GDate, this
* function returns FALSE returns FALSE
@@ -209,12 +210,12 @@
* is responsible for making sure the field exists and has the correct type.
*
* @param fieldname the name of a field
- * @param value the Value class to set
+ * @param fraction the Fraction class to set
* @return TRUE if the value could be set correctly. If there was no field
* with fieldname or the existing field did not contain a Fraction, this
* function returns FALSE returns FALSE
*/
- bool get_fraction(const Glib::ustring& fieldname, int& value_numerator, int& value_denominator) const;
+ bool get_fraction(const Glib::ustring& fieldname, Gst::Fraction& fraction) const;
/** Calls the provided slot once for each field in the Structure. In contrast
* to foreach(), the function may modify but not delete the fields. The
Modified: gstreamermm/trunk/gstreamer/src/value.ccg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/value.ccg (original)
+++ gstreamermm/trunk/gstreamer/src/value.ccg Wed Mar 19 22:41:43 2008
@@ -22,6 +22,54 @@
namespace Gst
{
+Fourcc::Fourcc() : first(0), second(0), third(0), fourth(0)
+{}
+
+Fourcc::Fourcc(char first, char second, char third, char fourth)
+: first(first), second(second), third(third), fourth(fourth)
+{}
+
+Fourcc::Fourcc(const Glib::ustring& s)
+: first(0), second(0), third(0), fourth(0)
+{
+ guint32 fourcc = GST_STR_FOURCC(s.c_str());
+ get_ccs(fourcc);
+
+}
+
+Fourcc::Fourcc(guint32 fourcc)
+: first(0), second(0), third(0), fourth(0)
+{
+ get_ccs(fourcc);
+}
+
+Fourcc::Fourcc(const Fourcc& f)
+: first(f.first), second(f.second), third(f.third), fourth(f.fourth)
+{}
+
+Fourcc::Fourcc(const Glib::ValueBase& value)
+: first(0), second(0), third(0), fourth(0)
+{
+ if(G_VALUE_TYPE(value.gobj()) == GST_TYPE_FOURCC)
+ {
+ int fourcc = gst_value_get_fourcc(value.gobj());
+ get_ccs(fourcc);
+ }
+}
+
+guint32 Fourcc::get_fourcc() const
+{
+ return GST_MAKE_FOURCC(first, second, third, fourth);
+}
+
+void Fourcc::get_ccs(guint32 fourcc)
+{
+ first = fourcc & 0xff;
+ second = (fourcc >> 8) & 0xff;
+ third = (fourcc >> 16) & 0xff;
+ fourth = (fourcc >> 24) & 0xff;
+}
+
Fraction::Fraction() : num(0), denom(1)
{}
Modified: gstreamermm/trunk/gstreamer/src/value.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/value.hg (original)
+++ gstreamermm/trunk/gstreamer/src/value.hg Wed Mar 19 22:41:43 2008
@@ -27,11 +27,78 @@
namespace Gst
{
+/** Represents a 4 byte identifier (used in codecs) for use to store in
+ * Structures of Caps as a value representing a property (see GStreamer
+ * Application Development Manual section 8.2.2 and GstValue docs 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::Fourcc> value;
+ * value.init(Glib::Value<Gst::Fourcc>::value_type());
+ * value.set(Gst::Fourcc('M', 'J', 'P', 'G'));
+ *
+ * Gst::Structure structure("my-structure");
+ * structure.set_field("id", value);
+ * ...
+ * Glib::ValueBase gst_value;
+ * structure.get_field("id", gst_value);
+ * Gst::Fourcc fourcc(gst_value);
+ * char first_char = fourcc.first;
+ * ...
+ * @endcode
+ */
+class Fourcc
+{
+public:
+ /** Construct an undefined Fourcc
+ */
+ Fourcc();
+
+ /** Construct a Fourcc from 4 characters
+ */
+ Fourcc(char first, char second, char third, char fourth);
+
+ /** Construct a Fourcc from an input string. Caller is responsible for
+ * ensuring the input string consists of at least four characters.
+ */
+ Fourcc(const Glib::ustring& s);
+
+ /** Construct a Fourcc from a 32 bit unsigned integer
+ */
+ Fourcc(guint32 fourcc);
+
+ /** Construct a Fourcc from another
+ */
+ Fourcc(const Fourcc& f);
+
+ /** Cosntruct a Fourcc from a GST_TYPE_FOURCC
+ */
+ Fourcc(const Glib::ValueBase& gst_fraction_value);
+
+public:
+ /** Gets the four characters converted into a guint32 fourcc value with host
+ * endianness.
+ */
+ guint32 get_fourcc() const;
+
+public:
+ char first;
+ char second;
+ char third;
+ char fourth;
+
+private:
+ void get_ccs(guint32 fourcc);
+};
+
/** 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). 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:
+ * section 8.2.2 and GstValue docs 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> value;
@@ -51,10 +118,22 @@
class Fraction
{
public:
+ /** Constructs a zero Fraction (0/1)
+ */
Fraction();
+
+ /** Constructs a Fraction (num/denom)
+ */
Fraction(int num, int denom);
+
+ /** Constructs a Fraction from another
+ */
Fraction(const Fraction& f);
+
+ /** Constructs a Fraction from a GST_TYPE_FRACTION
+ */
Fraction(const Glib::ValueBase& gst_fraction_value);
+
public:
int num;
int denom;
@@ -62,10 +141,10 @@
/** 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). 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:
+ * Development Manual section 8.2.2 and GstValue docs 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> value;
@@ -85,10 +164,22 @@
class IntRange
{
public:
+ /** Constructs a zero IntRange (0 - 0)
+ */
IntRange();
+
+ /** Constructs an IntRange (min - max)
+ */
IntRange(int min, int max);
+
+ /** Constructs an IntRange from another
+ */
IntRange(const IntRange& r);
+
+ /** Constructs an IntRange from a GST_TYPE_INT_RANGE
+ */
IntRange(const Glib::ValueBase& gst_int_range_value);
+
public:
int min;
int max;
@@ -96,10 +187,10 @@
/** 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:
+ * Development Manual section 8.2.2 and GstValue docs 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> value;
@@ -119,10 +210,22 @@
class DoubleRange
{
public:
+ /** Constructs a zero DoubleRange (0.0 - 0.0)
+ */
DoubleRange();
+
+ /** Constructs a DoubleRange (min - max)
+ */
DoubleRange(double min, double max);
+
+ /** Constructs a DoubleRange from another
+ */
DoubleRange(const DoubleRange& r);
+
+ /** Constructs a DoubleRange from a GST_TYPE_DOUBLE_RANGE
+ */
DoubleRange(const Glib::ValueBase& gst_double_range_value);
+
public:
double min;
double max;
@@ -130,9 +233,10 @@
/** 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). 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:
+ * section 8.2.2 and GstValue docs 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> value;
@@ -152,10 +256,22 @@
class FractionRange
{
public:
+ /** Constructs a zero FractionRange (0/1 - 0/1)
+ */
FractionRange();
+
+ /** Constructs a FractionRange (min - max)
+ */
FractionRange(const Fraction& min, const Fraction& max);
+
+ /** Constructs a FractionRange from another
+ */
FractionRange(const FractionRange& r);
+
+ /** Constructs a FractionRange from a GST_TYPE_FRACTION_RANGE
+ */
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 19 22:41:43 2008
@@ -20,6 +20,7 @@
*/
#include <gstreamermm.h>
+#include <glibmm/date.h>
#include <iostream>
int main (int argc, char* argv[])
@@ -44,7 +45,13 @@
rangeValue.init(Glib::Value<Gst::FractionRange>::value_type());
rangeValue.set(Gst::FractionRange(Gst::Fraction(1,2), Gst::Fraction(3,4)));
- structure.set_field(Glib::Quark("string"), stringValue).set_field("integer", intValue).set_field("fraction", fractValue).set_field("range", rangeValue);
+ Glib::Date date;
+ date.set_time_current();
+ Glib::Value<Glib::Date> dateValue;
+ dateValue.init(Glib::Value<Glib::Date>::value_type());
+ dateValue.set(date);
+
+ structure.set_field(Glib::Quark("string"), stringValue).set_field("integer", intValue).set_field("fraction", fractValue).set_field("range", rangeValue).set_field("date", dateValue);
Glib::Value<Glib::ustring> value1;
structure.get_field("string", value1);
@@ -67,5 +74,11 @@
range.min.denom << "), (" << range.max.num << "/" << range.max.denom <<
")]'" << std::endl;
+ Glib::ValueBase value5;
+ structure.get_field("date", value5);
+ Glib::Date date_copy(*gst_value_get_date(value5.gobj()));
+ std::cout << "date value = " << date_copy.get_month() << "/" <<
+ (int) date_copy.get_day() << "/" << date_copy.get_year() << std::endl;
+
return 0;
}
Modified: gstreamermm/trunk/tools/m4/class_boxedtype_ncopy.m4
==============================================================================
--- gstreamermm/trunk/tools/m4/class_boxedtype_ncopy.m4 (original)
+++ gstreamermm/trunk/tools/m4/class_boxedtype_ncopy.m4 Wed Mar 19 22:41:43 2008
@@ -1,5 +1,6 @@
dnl Modified from class_boxed_type.m4 in glibmm (designed to work in a similar
-dnl fashion except that the gobject is not copied if it can be helped)
+dnl fashion except that the gobject is not copied if it can be helped and
+dnl destruction of underlying gobject at wrapper destruction is flexible)
define(`_CLASS_BOXEDTYPE_NCOPY',`dnl
_PUSH()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]