#include <stdio.h>
#include <gst/gst.h>

gboolean have_buffer (GstPad * pad, GstBuffer * buf, gpointer u_data)
{
  gst_util_dump_mem (GST_BUFFER_DATA (buf), 16);
  return TRUE;
}

int main (int argc, char **argv)
{
    GstElement *pipeline, *src, *volume, *sink;
    GstStateChangeReturn sret;
    GstPad *pad;

    gst_init (&argc, &argv);

    pipeline = gst_pipeline_new ("pipe");
    src = gst_element_factory_make ("pulsesrc", "src"),
    volume = gst_element_factory_make ("volume", "volume");
    sink = gst_element_factory_make ("pulsesink", "sink");

    gst_bin_add_many (GST_BIN (pipeline), src, volume, sink, NULL);
    gst_element_link_many (src, volume, sink, NULL);

    pad = gst_element_get_static_pad (volume, "sink");
    gst_pad_add_buffer_probe (pad, G_CALLBACK (have_buffer), NULL);
    gst_object_unref (pad);

    sret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
    g_print ("Pipeline to PLAYING: %d\n", sret);

    getchar ();
    sret = gst_element_set_state (pipeline, GST_STATE_READY);
    g_print ("Pipeline to NULL: %d\n", sret);    

    getchar ();
    sret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
    g_print ("Pipeline to PLAYING: %d\n", sret);

    getchar ();
    sret = gst_element_set_state (pipeline, GST_STATE_NULL);
    g_print ("Pipeline to NULL: %d\n", sret);

    gst_object_unref (GST_OBJECT (pipeline));

    return 0;
}

