Esempio n. 1
0
static extern bool gst_control_source_get_value_array (IntPtr raw, ulong timestamp, ref GstValueArray value_array);
Esempio n. 2
0
public System.Array GetValueArray (ulong timestamp, int nsamples, ulong interval) {
  GstValueArray va = new GstValueArray ();
  Gst.GLib.Value v = Gst.GLib.Value.Empty;

  if (!GetValue (0, ref v))
    return null;

  System.Type t = v.Val.GetType ();
  v.Dispose ();

  bool supported = false;
  foreach (System.Type tmp in supported_types)
    if (tmp == t)
      supported = true;
  if (!supported)
    throw new Exception ("Unsupported type '" + t + "'");

  int eltsize = Marshal.SizeOf (t);
  va.values = g_try_malloc (eltsize * nsamples);
  if (va.values == IntPtr.Zero)
    throw new OutOfMemoryException ();

  va.nbsamples = nsamples;
  va.sample_interval = interval;

  bool raw_ret = gst_control_source_get_value_array (Handle, timestamp, ref va);

  if (!raw_ret) {
    Gst.GLib.Marshaller.Free (va.values);
    return null;
  }

  System.Array values = Array.CreateInstance (t, nsamples);

  if (t == typeof (string)) {
    string[] ret = (string[]) values;

    for (int i = 0; i < nsamples; i++) {
      IntPtr str = Marshal.ReadIntPtr (va.values, i * IntPtr.Size);
      ret[i] = Gst.GLib.Marshaller.PtrToStringGFree (str);
    }
  } else if (t == typeof (short)) {
    short[] ret = (short[]) values;

    for (int i = 0; i < nsamples; i++) {
      ret[i] = Marshal.ReadInt16 (va.values, i * 2);
    }
  } else if (t == typeof (ushort)) {
    ushort[] ret = (ushort[]) values;

    for (int i = 0; i < nsamples; i++) {
      ret[i] = (ushort) Marshal.ReadInt16 (va.values, i * 2);
    }
  } else if (t == typeof (int)) {
    int[] ret = (int[]) values;

    for (int i = 0; i < nsamples; i++) {
      ret[i] = Marshal.ReadInt32 (va.values, i * 4);
    }
  } else if (t == typeof (uint)) {
    uint[] ret = (uint[]) values;

    for (int i = 0; i < nsamples; i++) {
      ret[i] = (uint) Marshal.ReadInt32 (va.values, i * 4);
    }
  } else if (t == typeof (long)) {
    long[] ret = (long[]) values;

    for (int i = 0; i < nsamples; i++) {
      ret[i] = Marshal.ReadInt64 (va.values, i * 8);
    }
  } else if (t == typeof (ulong)) {
    ulong[] ret = (ulong[]) values;

    for (int i = 0; i < nsamples; i++) {
      ret[i] = (ulong) Marshal.ReadInt64 (va.values, i * 8);
    }
  } else if (t == typeof (float)) {
    float[] ret = (float[]) values;
    Marshal.Copy (va.values, ret, 0, nsamples);
  } else if (t == typeof (double)) {
    double[] ret = (double[]) values;
    Marshal.Copy (va.values, ret, 0, nsamples);
  } else if (t == typeof (bool)) {
    bool[] ret = (bool[]) values;

    for (int i = 0; i < nsamples; i++) {
      ret[i] = Marshal.ReadInt32 (va.values, i * 4) != 0;
    }
  }

  Gst.GLib.Marshaller.Free (va.values);

  return values;
}
Esempio n. 3
0
  public bool NativeCallback (IntPtr raw, ulong timestamp, ref GstValueArray va) {
    try {
      System.Array values = managed (timestamp, va.nbsamples, va.sample_interval);
      if (values == null)
        return false;

      System.Type t = values.GetType ();
      if (t == typeof (string[])) {
        string[] ret = (string[]) values;

        for (int i = 0; i < va.nbsamples; i++) {
          Marshal.WriteIntPtr (va.values, i * IntPtr.Size, Gst.GLib.Marshaller.StringToPtrGStrdup (ret[i]));
        }
      } else if (t == typeof (short[])) {
        short[] ret = (short[]) values;

        for (int i = 0; i < va.nbsamples; i++) {
          Marshal.WriteInt16 (va.values, i * 2, ret[i]);
        }
      } else if (t == typeof (ushort[])) {
        ushort[] ret = (ushort[]) values;

        for (int i = 0; i < va.nbsamples; i++) {
          Marshal.WriteInt16 (va.values, i * 2, (short) ret[i]);
        }
      } else if (t == typeof (int[])) {
        int[] ret = (int[]) values;

        for (int i = 0; i < va.nbsamples; i++) {
          Marshal.WriteInt32 (va.values, i * 4, ret[i]);
        }
      } else if (t == typeof (uint[])) {
        uint[] ret = (uint[]) values;

        for (int i = 0; i < va.nbsamples; i++) {
          Marshal.WriteInt32 (va.values, i * 4, (int) ret[i]);
        }
      } else if (t == typeof (long[])) {
        long[] ret = (long[]) values;

        for (int i = 0; i < va.nbsamples; i++) {
          Marshal.WriteInt64 (va.values, i * 8, ret[i]);
        }
      } else if (t == typeof (ulong[])) {
        ulong[] ret = (ulong[]) values;

        for (int i = 0; i < va.nbsamples; i++) {
          Marshal.WriteInt64 (va.values, i * 8, (long) ret[i]);
        }
      } else if (t == typeof (float[])) {
        float[] ret = (float[]) values;
        Marshal.Copy (ret, 0, va.values, va.nbsamples);
      } else if (t == typeof (double[])) {
        double[] ret = (double[]) values;
        Marshal.Copy (ret, 0, va.values, va.nbsamples);
      } else if (t == typeof (bool[])) {
        bool[] ret = (bool[]) values;

        for (int i = 0; i < va.nbsamples; i++) {
          Marshal.WriteInt32 (va.values, i * 4, ret[i] == false ? 0 : 1);
        }
      }

      return true;
    } catch (Exception e) {
      Gst.GLib.ExceptionManager.RaiseUnhandledException (e, true);
      // NOTREACHED: Above call does not return.
      throw e;
    }
  }