perl-GStreamer r87 - in trunk: . t xs



Author: tsch
Date: Wed Nov 26 20:58:26 2008
New Revision: 87
URL: http://svn.gnome.org/viewvc/perl-GStreamer?rev=87&view=rev

Log:
Add support for GST_TYPE_FOURCC, GST_TYPE_DOUBLE_RANGE, GST_TYPE_ARRAY,
GST_TYPE_FRACTION, and GST_TYPE_FRACTION_RANGE.


Modified:
   trunk/ChangeLog
   trunk/t/GstValue.t
   trunk/xs/GstValue.xs

Modified: trunk/t/GstValue.t
==============================================================================
--- trunk/t/GstValue.t	(original)
+++ trunk/t/GstValue.t	Wed Nov 26 20:58:26 2008
@@ -16,17 +16,36 @@
 my $structure = {
   name => "urgs",
   fields => [
-    [field_one => "GStreamer::IntRange" => [23, 42]],
-    [field_two => "GStreamer::ValueList" => [[23, "Glib::Int"], [42, "Glib::Int"]]],
-    [field_three => "GStreamer::ValueList" => [[[23, 42], "GStreamer::IntRange"]]],
-    [field_four => "GStreamer::Date" => $time]
+    [fourcc                => "GStreamer::Fourcc"        => "MJPG"],
+    [int_range             => "GStreamer::IntRange"      => [23, 42]],
+    [double_range          => "GStreamer::DoubleRange"   => [23, 42]],
+    [value_list_int        => "GStreamer::ValueList"     => [[23, "Glib::Int"], [42, "Glib::Int"]]],
+    [value_list_int_range  => "GStreamer::ValueList"     => [[[23, 42], "GStreamer::IntRange"]]],
+    [value_array_int       => "GStreamer::ValueArray"    => [[23, "Glib::Int"], [42, "Glib::Int"]]],
+    [value_array_int_range => "GStreamer::ValueArray"    => [[[23, 42], "GStreamer::IntRange"]]],
+    [fraction              => "GStreamer::Fraction"      => [23, 42]],
+    [fraction_range        => "GStreamer::FractionRange" => [[23, 42], [42, 23]]],
+    [date                  => "GStreamer::Date"          => $time]
   ]
 };
 
 my $string = GStreamer::Structure::to_string($structure);
 
-# remove trailing semicolon that start to appear sometime in the past
+# remove trailing semicolon that started to appear sometime in the past
 $string =~ s/;\Z//;
 
-is($string, "urgs, field_one=(int)[ 23, 42 ], field_two=(int){ 23, 42 }, field_three=(int){ [ 23, 42 ] }, field_four=(GstDate)2001-09-09");
+my $exptected_string =
+    "urgs, "
+  . "fourcc=(fourcc)MJPG, "
+  . "int_range=(int)[ 23, 42 ], "
+  . "double_range=(double)[ 23, 42 ], "
+  . "value_list_int=(int){ 23, 42 }, "
+  . "value_list_int_range=(int){ [ 23, 42 ] }, "
+  . "value_array_int=(int)< 23, 42 >, "
+  . "value_array_int_range=(int)< [ 23, 42 ] >, "
+  . "fraction=(fraction)23/42, "
+  . "fraction_range=(fraction)[ 23/42, 42/23 ], "
+  . "date=(GstDate)2001-09-09";
+
+is($string, $exptected_string);
 is_deeply(GStreamer::Structure::from_string($string), $structure);

Modified: trunk/xs/GstValue.xs
==============================================================================
--- trunk/xs/GstValue.xs	(original)
+++ trunk/xs/GstValue.xs	Wed Nov 26 20:58:26 2008
@@ -22,6 +22,86 @@
 
 /* ------------------------------------------------------------------------- */
 
+static GPerlValueWrapperClass gst2perl_fourcc_wrapper_class;
+
+static SV *
+gst2perl_fourcc_wrap (const GValue *value)
+{
+	return newSVpvf ("%" GST_FOURCC_FORMAT,
+	                 GST_FOURCC_ARGS (gst_value_get_fourcc (value)));
+;
+}
+
+static void
+gst2perl_fourcc_unwrap (GValue *value, SV *sv)
+{
+	STRLEN length = 0;
+	const char *string = SvPV (sv, length);
+	if (length != 4)
+		croak ("GStreamer::Fourcc values must be strings of length 4");
+	gst_value_set_fourcc (value, GST_STR_FOURCC (string));
+}
+
+static void
+gst2perl_fourcc_initialize (void)
+{
+	gst2perl_fourcc_wrapper_class.wrap = gst2perl_fourcc_wrap;
+	gst2perl_fourcc_wrapper_class.unwrap = gst2perl_fourcc_unwrap;
+
+	gperl_register_fundamental_full (GST_TYPE_FOURCC,
+	                                 "GStreamer::Fourcc",
+	                                 &gst2perl_fourcc_wrapper_class);
+}
+
+/* ------------------------------------------------------------------------- */
+
+static GPerlValueWrapperClass gst2perl_double_range_wrapper_class;
+
+static SV *
+gst2perl_double_range_wrap (const GValue *value)
+{
+	AV *av = newAV ();
+
+	av_push (av, newSVnv (gst_value_get_double_range_min (value)));
+	av_push (av, newSVnv (gst_value_get_double_range_max (value)));
+
+	return newRV_noinc ((SV *) av);
+}
+
+static void
+gst2perl_double_range_unwrap (GValue *value, SV *sv)
+{
+	AV *av;
+	SV **start, **end;
+
+	if (!SvOK (sv) || !SvRV (sv) || SvTYPE (SvRV (sv)) != SVt_PVAV)
+		croak ("GStreamer::DoubleRange values must be array references");
+
+	av = (AV *) SvRV (sv);
+
+	if (av_len (av) != 1)
+		croak ("GStreamer::DoubleRange values must contain two values: start and end");
+
+	start = av_fetch (av, 0, 0);
+	end = av_fetch (av, 1, 0);
+
+	if (start && SvOK (*start) && end && SvOK (*end))
+		gst_value_set_double_range (value, SvNV (*start), SvNV (*end));
+}
+
+static void
+gst2perl_double_range_initialize (void)
+{
+	gst2perl_double_range_wrapper_class.wrap = gst2perl_double_range_wrap;
+	gst2perl_double_range_wrapper_class.unwrap = gst2perl_double_range_unwrap;
+
+	gperl_register_fundamental_full (GST_TYPE_DOUBLE_RANGE,
+	                                 "GStreamer::DoubleRange",
+	                                 &gst2perl_double_range_wrapper_class);
+}
+
+/* ------------------------------------------------------------------------- */
+
 static GPerlValueWrapperClass gst2perl_int_range_wrapper_class;
 
 static SV *
@@ -122,7 +202,12 @@
 		if (element && SvOK (*element) && type && SvOK (*type)) {
 			GValue new_value = { 0, };
 
-			g_value_init (&new_value, gperl_type_from_package (SvPV_nolen (*type)));
+			const char *package = SvPV_nolen (*type);
+			GType gtype = gperl_type_from_package (package);
+			if (!type)
+				croak ("unregistered package %s encountered", package);
+
+			g_value_init (&new_value, gtype);
 			/* FIXME: Can this cause deadlocks? */
 			gperl_value_from_sv (&new_value, *element);
 			gst_value_list_append_value (value, &new_value);
@@ -146,6 +231,197 @@
 
 /* ------------------------------------------------------------------------- */
 
+/* This array stuff is a copy of the list stuff. */
+
+static GPerlValueWrapperClass gst2perl_value_array_wrapper_class;
+
+static SV *
+gst2perl_value_array_wrap (const GValue *value)
+{
+	AV *av = newAV ();
+	guint size, i;
+
+	size = gst_value_array_get_size (value);
+	for (i = 0; i < size; i++) {
+		const GValue *list_value = gst_value_array_get_value (value, i);
+		AV *list_av = newAV ();
+
+		/* FIXME: Can this cause deadlocks? */
+		av_push (list_av, gperl_sv_from_value (list_value));
+		av_push (list_av, newSVpv (gperl_package_from_type (G_VALUE_TYPE (list_value)), PL_na));
+
+		av_push (av, newRV_noinc ((SV *) list_av));
+	}
+
+	return newRV_noinc ((SV *) av);
+}
+
+static void
+gst2perl_value_array_unwrap (GValue *value, SV *sv)
+{
+	AV *av;
+	int i;
+
+	if (!SvOK (sv) || !SvRV (sv) || SvTYPE (SvRV (sv)) != SVt_PVAV)
+		croak ("GstValueArray must be an array reference");
+
+	av = (AV *) SvRV (sv);
+	for (i = 0; i <= av_len (av); i++) {
+		SV **list_value, **element, **type;
+		AV *list_av;
+
+		list_value = av_fetch (av, i, 0);
+
+		if (!list_value || !SvOK (*list_value) || !SvRV (*list_value) || SvTYPE (SvRV (*list_value)) != SVt_PVAV)
+			croak ("GstValueArray must contain array references");
+
+		list_av = (AV *) SvRV (*list_value);
+
+		if (av_len (list_av) != 1)
+			croak ("GstValueArray must contain array references with two elements: value and type");
+
+		element = av_fetch (list_av, 0, 0);
+		type = av_fetch (list_av, 1, 0);
+
+		if (element && SvOK (*element) && type && SvOK (*type)) {
+			GValue new_value = { 0, };
+
+			const char *package = SvPV_nolen (*type);
+			GType gtype = gperl_type_from_package (package);
+			if (!type)
+				croak ("unregistered package %s encountered", package);
+
+			g_value_init (&new_value, gtype);
+			/* FIXME: Can this cause deadlocks? */
+			gperl_value_from_sv (&new_value, *element);
+			gst_value_array_append_value (value, &new_value);
+
+			g_value_unset (&new_value);
+		}
+	}
+
+}
+
+static void
+gst2perl_value_array_initialize (void)
+{
+	gst2perl_value_array_wrapper_class.wrap = gst2perl_value_array_wrap;
+	gst2perl_value_array_wrapper_class.unwrap = gst2perl_value_array_unwrap;
+
+	gperl_register_fundamental_full (GST_TYPE_ARRAY,
+	                                 "GStreamer::ValueArray",
+	                                 &gst2perl_value_array_wrapper_class);
+}
+
+/* ------------------------------------------------------------------------- */
+
+static GPerlValueWrapperClass gst2perl_fraction_wrapper_class;
+
+static SV *
+gst2perl_fraction_wrap (const GValue *value)
+{
+	AV *av = newAV ();
+
+	av_push (av, newSViv (gst_value_get_fraction_numerator (value)));
+	av_push (av, newSViv (gst_value_get_fraction_denominator (value)));
+
+	return newRV_noinc ((SV *) av);
+}
+
+static void
+gst2perl_fraction_unwrap (GValue *value, SV *sv)
+{
+	AV *av;
+	SV **numerator, **denominator;
+
+	if (!SvOK (sv) || !SvRV (sv) || SvTYPE (SvRV (sv)) != SVt_PVAV)
+		croak ("GstFraction must be an array reference");
+
+	av = (AV *) SvRV (sv);
+
+	if (av_len (av) != 1)
+		croak ("GstFraction must contain two values: numerator and denominator");
+
+	numerator = av_fetch (av, 0, 0);
+	denominator = av_fetch (av, 1, 0);
+
+	if (numerator && SvOK (*numerator) && denominator && SvOK (*denominator))
+		gst_value_set_fraction (value, SvIV (*numerator), SvIV (*denominator));
+}
+
+static void
+gst2perl_fraction_initialize (void)
+{
+	gst2perl_fraction_wrapper_class.wrap = gst2perl_fraction_wrap;
+	gst2perl_fraction_wrapper_class.unwrap = gst2perl_fraction_unwrap;
+
+	gperl_register_fundamental_full (GST_TYPE_FRACTION,
+	                                 "GStreamer::Fraction",
+	                                 &gst2perl_fraction_wrapper_class);
+}
+
+/* ------------------------------------------------------------------------- */
+
+static GPerlValueWrapperClass gst2perl_fraction_range_wrapper_class;
+
+static SV *
+gst2perl_fraction_range_wrap (const GValue *value)
+{
+	AV *av = newAV ();
+
+	av_push (av, gperl_sv_from_value (gst_value_get_fraction_range_min (value)));
+	av_push (av, gperl_sv_from_value (gst_value_get_fraction_range_max (value)));
+
+	return newRV_noinc ((SV *) av);
+}
+
+static void
+gst2perl_fraction_range_unwrap (GValue *value, SV *sv)
+{
+	AV *av;
+	SV **start, **end;
+
+	if (!SvOK (sv) || !SvRV (sv) || SvTYPE (SvRV (sv)) != SVt_PVAV)
+		croak ("GstFractionRange must be an array reference");
+
+	av = (AV *) SvRV (sv);
+
+	if (av_len (av) != 1)
+		croak ("GstFractionRange must contain two values: start and end");
+
+	start = av_fetch (av, 0, 0);
+	end = av_fetch (av, 1, 0);
+
+	if (start && SvOK (*start) && end && SvOK (*end)) {
+		GValue start_value = { 0, }, end_value = { 0, };
+
+		g_value_init (&start_value, GST_TYPE_FRACTION);
+		g_value_init (&end_value, GST_TYPE_FRACTION);
+
+		/* FIXME: Can this cause deadlocks? */
+		gperl_value_from_sv (&start_value, *start);
+		gperl_value_from_sv (&end_value, *end);
+
+		gst_value_set_fraction_range (value, &start_value, &end_value);
+
+		g_value_unset (&start_value);
+		g_value_unset (&end_value);
+	}
+}
+
+static void
+gst2perl_fraction_range_initialize (void)
+{
+	gst2perl_fraction_range_wrapper_class.wrap = gst2perl_fraction_range_wrap;
+	gst2perl_fraction_range_wrapper_class.unwrap = gst2perl_fraction_range_unwrap;
+
+	gperl_register_fundamental_full (GST_TYPE_FRACTION_RANGE,
+	                                 "GStreamer::FractionRange",
+	                                 &gst2perl_fraction_range_wrapper_class);
+}
+
+/* ------------------------------------------------------------------------- */
+
 static GPerlBoxedWrapperClass gst2perl_date_wrapper_class;
 
 static SV *
@@ -205,18 +481,14 @@
 
 /* ------------------------------------------------------------------------- */
 
-/**
- * TODO: GST_TYPE_FOURCC
- * 	 GST_TYPE_DOUBLE_RANGE
- * 	 GST_TYPE_ARRAY
- * 	 GST_TYPE_FRACTION
- */
-
-/* ------------------------------------------------------------------------- */
-
 MODULE = GStreamer::Value	PACKAGE = GStreamer::Value	PREFIX = gst_value_
 
 BOOT:
+	gst2perl_fourcc_initialize ();
 	gst2perl_int_range_initialize ();
+	gst2perl_double_range_initialize ();
 	gst2perl_value_list_initialize ();
+	gst2perl_value_array_initialize ();
+	gst2perl_fraction_initialize ();
+	gst2perl_fraction_range_initialize ();
 	gst2perl_date_initialize ();



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