#include <gst/gst.h>
#include <gst/interfaces/mixer.h>

GMainLoop *loop;

static void
msg_volume_changed (GstBus * bus, GstMessage * message, GstElement * mixer)
{
  g_message ("new volume");
}

gboolean
timeout_cb (gpointer data) 
{
  g_main_quit (loop);
  return FALSE;
}

int
main (int argc, char *argv[])
{
  GstElement *mixer;
  GstBus *bus;

  GError *error = NULL;

  gst_init (&argc, &argv);

  bus = gst_bus_new ();

  mixer = gst_parse_launch ("alsamixer", &error);
  if (error) {
    g_print ("pipeline could not be constructed: %s\n", error->message);
    g_error_free (error);
    return 1;
  }
  
  gst_element_set_bus (GST_ELEMENT (mixer), bus);

  gst_element_set_state (mixer, GST_STATE_PLAYING);
  gst_mixer_list_tracks (GST_MIXER (mixer));

  loop = g_main_loop_new (NULL, TRUE);
  
  g_return_val_if_fail (bus != NULL, 1);

  gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);

  g_signal_connect (bus, "message::volume-changed", (GCallback) msg_volume_changed, mixer);

  g_timeout_add (10 * 1000, timeout_cb, NULL);

  g_main_loop_run (loop);
  gst_element_set_state (mixer, GST_STATE_NULL);
  gst_object_unref (mixer);

  g_main_loop_unref (loop);
  return 0;
}

