/* Compile with :
 * gcc `pkg-config --cflags --libs gstreamer-plugins-base-0.10` -lgstinterfaces-0.10 -o audio audio.c
 * (uh... how come no .pc file gives the -lgstinterfaces-0.10 !?)
*/
#include <gst/gst.h>
#include <gst/interfaces/propertyprobe.h>

int
main (int argc, char *argv [])
{
  GstElement *elt = NULL;
  GstState current;
  GstPropertyProbe *probe = NULL;
  const GParamSpec *pspec = NULL;
  GValueArray *array = NULL;
  gint index = 0;
  GValue *device = NULL;
  gchar *name = NULL;

  gst_init (&argc, &argv);

  elt = gst_element_factory_make ("alsasink", "test");

  if (elt == NULL) {

    g_print ("No alsasink element available");
    return;
  }

  gst_element_set_state (elt, GST_STATE_PAUSED);

  probe = GST_PROPERTY_PROBE (elt);
  pspec = gst_property_probe_get_property (probe, "device");

  array = gst_property_probe_probe_and_get_values (probe, pspec);
  if (array == NULL) {

    g_print ("No device property to probe");
    gst_object_unref (GST_OBJECT (elt));
    return;
  }

  for (index = 0; index < array->n_values; index++) {

    device = g_value_array_get_nth (array, index);
    g_object_set_property (G_OBJECT (elt), "device", device);

    g_object_get (G_OBJECT (elt), "device-name", &name, NULL);
    if (name)
      g_print ("alsasink device=%s name=%s\n", g_value_get_string (device), name);
    else
      g_print ("alsasink device=%s name=(none)\n", g_value_get_string (device));
  }
  
  return 0;
}
