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

static GstElement *pipeline, *src;
static GMainLoop *loop;

static void
_src_pad_added_cb (GstElement * src, GstPad * pad, gpointer data)
{
  g_debug ("Rtspsrc pad added : %s:%s", GST_DEBUG_PAD_NAME (pad));
  g_debug ("It works!");

  g_main_loop_quit (loop);
}

gboolean
_timeout (gpointer data)
{
  gst_element_set_state (src, GST_STATE_PLAYING);

  return FALSE;
}

int main (int argc, char *argv[])
{
  gst_init (&argc, &argv);

  pipeline = gst_pipeline_new ("pipeline");
  src = gst_element_factory_make ("rtspsrc", NULL);
  gst_bin_add (GST_BIN (pipeline), src);
  g_signal_connect (src, "pad-added", (GCallback) _src_pad_added_cb, NULL);
  g_object_set (src, "location", argv[1], NULL);

  gst_element_set_state (pipeline, GST_STATE_PLAYING);

  /* Uncomment the next line to 'fix' it */
  //g_timeout_add (1000, _timeout, NULL);

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

  return 0;
}
