#include <ges/ges.h>

static void
bus_message_cb (GstBus * bus, GstMessage * message, GMainLoop * mainloop)
{
  switch (GST_MESSAGE_TYPE (message)) {
    case GST_MESSAGE_EOS:
      g_printerr ("Done\n");
      g_main_loop_quit (mainloop);
      break;
    default:
      break;
  }
}

int
main (int argc, char *argv[])
{
  GESTimeline *timeline;
  GESTrack *tracka = NULL;
  GESTrack *trackv = NULL;
  GESTimelineLayer *layer;
  GESTimelineTestSource *testsrca;
  GMainLoop *mainloop;
  GESTimelinePipeline *pipeline;
  GstBus *bus;


  gst_init (&argc, &argv);
  ges_init ();

  /*create the expected timeline */
  timeline = ges_timeline_new ();
  pipeline = ges_timeline_pipeline_new ();
  mainloop = g_main_loop_new (NULL, FALSE);

  /* create the tracks */

  trackv = ges_track_video_raw_new ();
  ges_timeline_add_track (timeline, trackv);

  tracka = ges_track_audio_raw_new ();
  ges_timeline_add_track (timeline, tracka);

  /* create the layer */
  layer = ges_timeline_layer_new ();
  g_object_set (layer, "priority", (gint32) 0, NULL);

  ges_timeline_add_layer (timeline, layer);

  /* create the sources */
  testsrca = ges_timeline_test_source_new ();
  ges_timeline_test_source_set_vpattern (testsrca, GES_VIDEO_TEST_PATTERN_RED);
  g_object_set (testsrca, "volume", (gdouble) 1, "freq", (gdouble) 880,
      "duration", (gint64) 2500000000LL, "start", (gint64) 1200000000LL,
      "in_point", (gint64) 0LL, "priority", (gint64) 0LL, NULL);

  ges_timeline_layer_add_object (layer, GES_TIMELINE_OBJECT (testsrca));

  ges_timeline_pipeline_add_timeline (pipeline, timeline);
  ges_timeline_pipeline_set_mode (pipeline, TIMELINE_MODE_PREVIEW_VIDEO);
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  gst_bus_add_signal_watch (bus);
  g_signal_connect (bus, "message", G_CALLBACK (bus_message_cb), mainloop);
  gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
  g_main_loop_run (mainloop);
  gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
  return 0;
}
