/*
 * Test code to reproduce audiosink bug
 *
 * compile with : gcc -o tst tst2.c `pkg-config gstreamer-1.0 --libs --cflags`
 *
 */
#include <gst/gst.h>

int main (int argc, char *argv[])
{
  GstElement *pipeline, *src, *sink;
  GMainLoop *loop;
  GstState state, pending;

  gst_init (&argc, &argv);

  pipeline = gst_pipeline_new ("pipeline");
  gst_element_set_state (pipeline, GST_STATE_PLAYING);
  src = gst_element_factory_make ("audiotestsrc", NULL);
  sink = gst_element_factory_make ("pulsesink", NULL);
  // Uncomment to make it work with autoaudiosink
  //sink = gst_element_factory_make ("autoaudiosink", NULL);
  gst_bin_add (GST_BIN (pipeline), src);
  gst_bin_add (GST_BIN (pipeline), sink);
  gst_element_link (src, sink);
  // Set to FALSE to make it work with pulsesink
  if (TRUE) {
    gst_element_set_state (sink, GST_STATE_PLAYING);
    gst_element_set_state (src, GST_STATE_PLAYING);
    gst_element_get_state (sink, &state, &pending, -1);
    g_debug ("state : %d - %d", state, pending);
  } else {
    gst_element_set_state (sink, GST_STATE_PAUSED);
    gst_element_set_state (src, GST_STATE_PLAYING);
    gst_element_get_state (sink, &state, &pending, -1);
    g_debug ("state : %d - %d", state, pending);
    gst_element_set_state (sink, GST_STATE_PLAYING);
  }

  loop = g_main_loop_new (NULL, FALSE);
  g_main_loop_run (loop);
  g_main_loop_unref (loop);

  return 0;
}
