Fix indention and use new Gst.Value stuff for dynamic signals

This commit is contained in:
Sebastian Dröge 2009-04-11 17:57:11 +02:00
parent d45b43983e
commit e03a50aa84
3 changed files with 102 additions and 106 deletions

View file

@ -136,17 +136,12 @@ namespace Gst {
static void OnMarshal (IntPtr closure, ref GLib.Value retval, uint argc, IntPtr argsPtr, static void OnMarshal (IntPtr closure, ref GLib.Value retval, uint argc, IntPtr argsPtr,
IntPtr ihint, IntPtr data) { IntPtr ihint, IntPtr data) {
object [] args = new object[argc - 1]; object [] args = new object[argc - 1];
object o = ( (GLib.Value) Marshal.PtrToStructure (argsPtr, typeof (GLib.Value))).Val; object o = Gst.Value.GetValue ( (GLib.Value) Marshal.PtrToStructure (argsPtr, typeof (GLib.Value)));
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
IntPtr struct_ptr = (IntPtr) ( (long) argsPtr + (i * gvalue_struct_size)); IntPtr struct_ptr = (IntPtr) ( (long) argsPtr + (i * gvalue_struct_size));
Type detectedType = GLib.GType.LookupType (Marshal.ReadIntPtr (struct_ptr)); GLib.Value argument = (GLib.Value) Marshal.PtrToStructure (struct_ptr, typeof (GLib.Value));
if (detectedType.IsSubclassOf (typeof (Opaque))) { args[i - 1] = Gst.Value.GetValue (argument);
args[i - 1] = (Opaque) Opaque.GetOpaque (g_value_peek_pointer (struct_ptr), detectedType, false);
} else {
GLib.Value argument = (GLib.Value) Marshal.PtrToStructure (struct_ptr, typeof (GLib.Value));
args[i - 1] = argument.Val;
}
} }
if (data == IntPtr.Zero) { if (data == IntPtr.Zero) {
@ -264,7 +259,7 @@ namespace Gst {
query = (SignalQuery) SignalEmitInfo[key]; query = (SignalQuery) SignalEmitInfo[key];
GLib.Value[] signal_parameters = new GLib.Value[query.n_params + 1]; GLib.Value[] signal_parameters = new GLib.Value[query.n_params + 1];
signal_parameters[0] = new GLib.Value (o); signal_parameters[0] = Gst.Value.CreateValue (o);
if (parameters.Length != query.n_params) if (parameters.Length != query.n_params)
throw new ApplicationException (String.Format ("Invalid number of parameters: expected {0}, got {1}", query.n_params, parameters.Length)); throw new ApplicationException (String.Format ("Invalid number of parameters: expected {0}, got {1}", query.n_params, parameters.Length));
@ -276,7 +271,7 @@ namespace Gst {
if (expected_type != given_type && ! given_type.IsSubclassOf (given_type)) if (expected_type != given_type && ! given_type.IsSubclassOf (given_type))
throw new ApplicationException (String.Format ("Invalid parameter type: expected {0}, got {1}", expected_type, given_type)); throw new ApplicationException (String.Format ("Invalid parameter type: expected {0}, got {1}", expected_type, given_type));
signal_parameters[i + 1] = new GLib.Value (parameters[i]); signal_parameters[i + 1] = Gst.Value.CreateValue (parameters[i]);
} }
GLib.Value return_value = new GLib.Value (); GLib.Value return_value = new GLib.Value ();
@ -288,7 +283,7 @@ namespace Gst {
g_signal_emitv (signal_parameters, query.signal_id, signal_detail_quark, ref return_value); g_signal_emitv (signal_parameters, query.signal_id, signal_detail_quark, ref return_value);
return (query.return_type != GType.Invalid && query.return_type != GType.None) ? return_value.Val : null; return (query.return_type != GType.Invalid && query.return_type != GType.None) ? Gst.Value.GetValue (return_value) : null;
} }
[DllImport ("gstreamersharpglue-0.10") ] [DllImport ("gstreamersharpglue-0.10") ]

View file

@ -2,26 +2,26 @@ protected MiniObject () : base (IntPtr.Zero)
{ {
} }
public static MiniObject NewFromValue (GLib.Value val) { public static MiniObject NewFromValue (GLib.Value val) {
IntPtr type = gstsharp_g_value_type (ref val); IntPtr type = gstsharp_g_value_type (ref val);
GLib.GType gtype = new GLib.GType (type); GLib.GType gtype = new GLib.GType (type);
return (MiniObject) GLib.Opaque.GetOpaque (gst_value_get_mini_object (ref val), (Type) gtype, false);
}
public static explicit operator GLib.Value (MiniObject o) { return (MiniObject) GLib.Opaque.GetOpaque (gst_value_get_mini_object (ref val), (Type) gtype, false);
GLib.Value val = new GLib.Value (new GLib.GType (gstsharp_g_type_from_instance (o.Handle))); }
gst_value_set_mini_object (ref val, o.Handle); public static explicit operator GLib.Value (MiniObject o) {
GLib.Value val = new GLib.Value (new GLib.GType (gstsharp_g_type_from_instance (o.Handle)));
return val; gst_value_set_mini_object (ref val, o.Handle);
}
[DllImport("gstreamersharpglue-0.10.dll")] return val;
private static extern IntPtr gstsharp_g_type_from_instance (IntPtr o); }
[DllImport("gstreamersharpglue-0.10.dll")]
private static extern IntPtr gstsharp_g_value_type (ref GLib.Value val); [DllImport ("gstreamersharpglue-0.10.dll") ]
[DllImport("gstreamer-0.10.dll")] private static extern IntPtr gstsharp_g_type_from_instance (IntPtr o);
private static extern IntPtr gst_value_get_mini_object (ref GLib.Value v); [DllImport ("gstreamersharpglue-0.10.dll") ]
[DllImport("gstreamer-0.10.dll")] private static extern IntPtr gstsharp_g_value_type (ref GLib.Value val);
private static extern void gst_value_set_mini_object (ref GLib.Value v, IntPtr o); [DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_value_get_mini_object (ref GLib.Value v);
[DllImport ("gstreamer-0.10.dll") ]
private static extern void gst_value_set_mini_object (ref GLib.Value v, IntPtr o);

View file

@ -28,36 +28,36 @@ namespace Gst {
return new Gst.List (val); return new Gst.List (val);
else if (type == Gst.Array.GType.Val) else if (type == Gst.Array.GType.Val)
return new Gst.Array (val); return new Gst.Array (val);
else if (((Type) gtype).IsSubclassOf (typeof (Gst.MiniObject))) else if ( ( (Type) gtype).IsSubclassOf (typeof (Gst.MiniObject)))
return MiniObject.NewFromValue (val); return MiniObject.NewFromValue (val);
else else
return val.Val; return val.Val;
} }
[DllImport("gstreamersharpglue-0.10.dll")] [DllImport ("gstreamersharpglue-0.10.dll") ]
private static extern IntPtr gstsharp_g_value_type (ref GLib.Value val); private static extern IntPtr gstsharp_g_value_type (ref GLib.Value val);
public static GLib.Value CreateValue (object o) { public static GLib.Value CreateValue (object o) {
if (o.GetType () == typeof (Fraction)) if (o.GetType () == typeof (Fraction))
return (GLib.Value) ((Fraction) o); return (GLib.Value) ( (Fraction) o);
else if (o.GetType () == typeof (DoubleRange)) else if (o.GetType () == typeof (DoubleRange))
return (GLib.Value) ((DoubleRange) o); return (GLib.Value) ( (DoubleRange) o);
else if (o.GetType () == typeof (IntRange)) else if (o.GetType () == typeof (IntRange))
return (GLib.Value) ((IntRange) o); return (GLib.Value) ( (IntRange) o);
else if (o.GetType () == typeof (FractionRange)) else if (o.GetType () == typeof (FractionRange))
return (GLib.Value) ((FractionRange) o); return (GLib.Value) ( (FractionRange) o);
else if (o.GetType () == typeof (Fourcc)) else if (o.GetType () == typeof (Fourcc))
return (GLib.Value) ((Fourcc) o); return (GLib.Value) ( (Fourcc) o);
else if (o.GetType () == typeof (Date)) else if (o.GetType () == typeof (Date))
return (GLib.Value) ((Date) o); return (GLib.Value) ( (Date) o);
else if (o.GetType () == typeof (DateTime)) else if (o.GetType () == typeof (DateTime))
return (GLib.Value) (new Date ((DateTime) o)); return (GLib.Value) (new Date ( (DateTime) o));
else if (o.GetType () == typeof (Gst.List)) else if (o.GetType () == typeof (Gst.List))
return (GLib.Value) ((Gst.List) o); return (GLib.Value) ( (Gst.List) o);
else if (o.GetType () == typeof (Gst.Array)) else if (o.GetType () == typeof (Gst.Array))
return (GLib.Value) ((Gst.Array) o); return (GLib.Value) ( (Gst.Array) o);
else if (o.GetType ().IsSubclassOf (typeof (Gst.MiniObject))) else if (o.GetType ().IsSubclassOf (typeof (Gst.MiniObject)))
return (GLib.Value) ((MiniObject) o); return (GLib.Value) ( (MiniObject) o);
else else
return new GLib.Value (o); return new GLib.Value (o);
} }
@ -71,10 +71,10 @@ namespace Gst {
set { set {
numerator = value; numerator = value;
Reduce (); Reduce ();
} }
} }
public int Denominator { public int Denominator {
get { get {
return denominator; return denominator;
@ -82,16 +82,16 @@ namespace Gst {
set { set {
if (denominator == 0) if (denominator == 0)
throw new ArgumentException (); throw new ArgumentException ();
denominator = value; denominator = value;
Reduce (); Reduce ();
} }
} }
private int numerator; private int numerator;
private int denominator; private int denominator;
public static GLib.GType GType { public static GLib.GType GType {
get { get {
return new GType (gst_fraction_get_type ()); return new GType (gst_fraction_get_type ());
@ -113,9 +113,9 @@ namespace Gst {
while (b != 0) { while (b != 0) {
int temp = a; int temp = a;
a = b; a = b;
b = temp % b; b = temp % b;
} }
return Math.Abs (a); return Math.Abs (a);
} }
@ -146,15 +146,15 @@ namespace Gst {
} }
public static explicit operator double (Fraction fraction) { public static explicit operator double (Fraction fraction) {
return ((double) fraction.numerator) / ((double) fraction.denominator); return ( (double) fraction.numerator) / ( (double) fraction.denominator);
} }
public static Fraction operator + (Fraction a, Fraction b) { public static Fraction operator + (Fraction a, Fraction b) {
return new Fraction ((a.Numerator * b.Denominator) + (b.Numerator * a.Denominator), a.Denominator * b.Denominator); return new Fraction ( (a.Numerator * b.Denominator) + (b.Numerator * a.Denominator), a.Denominator * b.Denominator);
} }
public static Fraction operator - (Fraction a, Fraction b) { public static Fraction operator - (Fraction a, Fraction b) {
return new Fraction ((a.Numerator * b.Denominator) - (b.Numerator * a.Denominator), a.Denominator * b.Denominator); return new Fraction ( (a.Numerator * b.Denominator) - (b.Numerator * a.Denominator), a.Denominator * b.Denominator);
} }
public static Fraction operator * (Fraction a, Fraction b) { public static Fraction operator * (Fraction a, Fraction b) {
@ -165,13 +165,13 @@ namespace Gst {
return new Fraction (a.Numerator * b.Denominator, a.Denominator * b.Numerator); return new Fraction (a.Numerator * b.Denominator, a.Denominator * b.Numerator);
} }
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern void gst_value_set_fraction (ref GLib.Value v, int numerator, int denominator); private static extern void gst_value_set_fraction (ref GLib.Value v, int numerator, int denominator);
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern int gst_value_get_fraction_numerator (ref GLib.Value v); private static extern int gst_value_get_fraction_numerator (ref GLib.Value v);
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern int gst_value_get_fraction_denominator (ref GLib.Value v); private static extern int gst_value_get_fraction_denominator (ref GLib.Value v);
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_fraction_get_type (); private static extern IntPtr gst_fraction_get_type ();
} }
@ -209,13 +209,13 @@ namespace Gst {
return val; return val;
} }
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_double_range_get_type (); private static extern IntPtr gst_double_range_get_type ();
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern void gst_value_set_double_range (ref GLib.Value v, double min, double max); private static extern void gst_value_set_double_range (ref GLib.Value v, double min, double max);
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern double gst_value_get_double_range_min (ref GLib.Value v); private static extern double gst_value_get_double_range_min (ref GLib.Value v);
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern double gst_value_get_double_range_max (ref GLib.Value v); private static extern double gst_value_get_double_range_max (ref GLib.Value v);
} }
@ -253,13 +253,13 @@ namespace Gst {
return val; return val;
} }
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_int_range_get_type (); private static extern IntPtr gst_int_range_get_type ();
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern void gst_value_set_int_range (ref GLib.Value v, int min, int max); private static extern void gst_value_set_int_range (ref GLib.Value v, int min, int max);
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern int gst_value_get_int_range_min (ref GLib.Value v); private static extern int gst_value_get_int_range_min (ref GLib.Value v);
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern int gst_value_get_int_range_max (ref GLib.Value v); private static extern int gst_value_get_int_range_max (ref GLib.Value v);
} }
@ -309,13 +309,13 @@ namespace Gst {
return val; return val;
} }
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_fraction_range_get_type (); private static extern IntPtr gst_fraction_range_get_type ();
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern void gst_value_set_fraction_range (ref GLib.Value v, ref GLib.Value min, ref GLib.Value max); private static extern void gst_value_set_fraction_range (ref GLib.Value v, ref GLib.Value min, ref GLib.Value max);
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_value_get_fraction_range_min (ref GLib.Value v); private static extern IntPtr gst_value_get_fraction_range_min (ref GLib.Value v);
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_value_get_fraction_range_max (ref GLib.Value v); private static extern IntPtr gst_value_get_fraction_range_max (ref GLib.Value v);
} }
@ -336,30 +336,30 @@ namespace Gst {
if (fourcc.Length != 4) if (fourcc.Length != 4)
throw new ArgumentException (); throw new ArgumentException ();
this.Val = (uint) ((((byte) fourcc[0]) << 24) | this.Val = (uint) ( ( ( (byte) fourcc[0]) << 24) |
(((byte) fourcc[1]) << 16) | ( ( (byte) fourcc[1]) << 16) |
(((byte) fourcc[2]) << 8) | ( ( (byte) fourcc[2]) << 8) |
(((byte) fourcc[3]) << 0)); ( ( (byte) fourcc[3]) << 0));
} }
public Fourcc (string fourcc) { public Fourcc (string fourcc) {
if (fourcc.Length != 4) if (fourcc.Length != 4)
throw new ArgumentException (); throw new ArgumentException ();
this.Val = (uint) ((((byte) fourcc[0]) << 24) | this.Val = (uint) ( ( ( (byte) fourcc[0]) << 24) |
(((byte) fourcc[1]) << 16) | ( ( (byte) fourcc[1]) << 16) |
(((byte) fourcc[2]) << 8) | ( ( (byte) fourcc[2]) << 8) |
(((byte) fourcc[3]) << 0)); ( ( (byte) fourcc[3]) << 0));
} }
public Fourcc (GLib.Value val) : this (gst_value_get_fourcc (ref val)) { public Fourcc (GLib.Value val) : this (gst_value_get_fourcc (ref val)) {
} }
public override string ToString () { public override string ToString () {
return String.Format ("{0}{1}{2}{3}", (char) ((Val >> 24) & 0xff), return String.Format ("{0}{1}{2}{3}", (char) ( (Val >> 24) & 0xff),
(char) ((Val >> 16) & 0xff), (char) ( (Val >> 16) & 0xff),
(char) ((Val >> 8) & 0xff), (char) ( (Val >> 8) & 0xff),
(char) ((Val >> 0) & 0xff)); (char) ( (Val >> 0) & 0xff));
} }
public static explicit operator GLib.Value (Fourcc fourcc) { public static explicit operator GLib.Value (Fourcc fourcc) {
@ -370,21 +370,22 @@ namespace Gst {
} }
public static explicit operator char[] (Fourcc fourcc) { public static explicit operator char[] (Fourcc fourcc) {
return new char[] {(char) ((fourcc.Val >> 24) & 0xff), return new char[] { (char) ( (fourcc.Val >> 24) & 0xff),
(char) ((fourcc.Val >> 16) & 0xff), (char) ( (fourcc.Val >> 16) & 0xff),
(char) ((fourcc.Val >> 8) & 0xff), (char) ( (fourcc.Val >> 8) & 0xff),
(char) ((fourcc.Val >> 0) & 0xff)}; (char) ( (fourcc.Val >> 0) & 0xff)
};
} }
public static explicit operator string (Fourcc fourcc) { public static explicit operator string (Fourcc fourcc) {
return fourcc.ToString (); return fourcc.ToString ();
} }
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_fourcc_get_type (); private static extern IntPtr gst_fourcc_get_type ();
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern void gst_value_set_fourcc (ref GLib.Value v, uint fourcc); private static extern void gst_value_set_fourcc (ref GLib.Value v, uint fourcc);
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern uint gst_value_get_fourcc (ref GLib.Value v); private static extern uint gst_value_get_fourcc (ref GLib.Value v);
} }
@ -418,7 +419,7 @@ namespace Gst {
public static explicit operator GLib.Value (Date date) { public static explicit operator GLib.Value (Date date) {
GLib.Value val = new GLib.Value (Date.GType); GLib.Value val = new GLib.Value (Date.GType);
IntPtr date_ptr = g_date_new_dmy ((byte) date.Val.Day, (int) date.Val.Month, (ushort) date.Val.Year); IntPtr date_ptr = g_date_new_dmy ( (byte) date.Val.Day, (int) date.Val.Month, (ushort) date.Val.Year);
gst_value_set_date (ref val, date_ptr); gst_value_set_date (ref val, date_ptr);
@ -427,20 +428,20 @@ namespace Gst {
return val; return val;
} }
[DllImport("libglib-2.0-0.dll")] [DllImport ("libglib-2.0-0.dll") ]
private static extern byte g_date_get_day (IntPtr date); private static extern byte g_date_get_day (IntPtr date);
[DllImport("libglib-2.0-0.dll")] [DllImport ("libglib-2.0-0.dll") ]
private static extern int g_date_get_month (IntPtr date); private static extern int g_date_get_month (IntPtr date);
[DllImport("libglib-2.0-0.dll")] [DllImport ("libglib-2.0-0.dll") ]
private static extern ushort g_date_get_year (IntPtr date); private static extern ushort g_date_get_year (IntPtr date);
[DllImport("libglib-2.0-0.dll")] [DllImport ("libglib-2.0-0.dll") ]
private static extern IntPtr g_date_new_dmy (byte day, int month, ushort year); private static extern IntPtr g_date_new_dmy (byte day, int month, ushort year);
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_date_get_type (); private static extern IntPtr gst_date_get_type ();
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_value_get_date (ref GLib.Value val); private static extern IntPtr gst_value_get_date (ref GLib.Value val);
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern void gst_value_set_date (ref GLib.Value val, IntPtr date); private static extern void gst_value_set_date (ref GLib.Value val, IntPtr date);
} }
@ -473,19 +474,19 @@ namespace Gst {
foreach (object o in l.content) { foreach (object o in l.content) {
GLib.Value v = Gst.Value.CreateValue (o); GLib.Value v = Gst.Value.CreateValue (o);
gst_value_list_append_value (ref val, ref v); gst_value_list_append_value (ref val, ref v);
} }
return val; return val;
} }
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_value_list_get_type (); private static extern IntPtr gst_value_list_get_type ();
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern uint gst_value_list_get_size (ref GLib.Value val); private static extern uint gst_value_list_get_size (ref GLib.Value val);
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_value_list_get_value (ref GLib.Value val, uint index); private static extern IntPtr gst_value_list_get_value (ref GLib.Value val, uint index);
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern void gst_value_list_append_value (ref GLib.Value val, ref GLib.Value el); private static extern void gst_value_list_append_value (ref GLib.Value val, ref GLib.Value el);
} }
@ -518,19 +519,19 @@ namespace Gst {
foreach (object o in a.content) { foreach (object o in a.content) {
GLib.Value v = Gst.Value.CreateValue (o); GLib.Value v = Gst.Value.CreateValue (o);
gst_value_array_append_value (ref val, ref v); gst_value_array_append_value (ref val, ref v);
} }
return val; return val;
} }
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_value_array_get_type (); private static extern IntPtr gst_value_array_get_type ();
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern uint gst_value_array_get_size (ref GLib.Value val); private static extern uint gst_value_array_get_size (ref GLib.Value val);
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern IntPtr gst_value_array_get_value (ref GLib.Value val, uint index); private static extern IntPtr gst_value_array_get_value (ref GLib.Value val, uint index);
[DllImport("gstreamer-0.10.dll")] [DllImport ("gstreamer-0.10.dll") ]
private static extern void gst_value_array_append_value (ref GLib.Value val, ref GLib.Value el); private static extern void gst_value_array_append_value (ref GLib.Value val, ref GLib.Value el);
} }
} }