#include <gst/gst.h>

gpointer thread_func1(gpointer data) {
  GstElement *pipeline;
  GstBus *bus;
  GstMessage *msg;

  /* Initialize GStreamer */

  /* Build the pipeline */
  pipeline = gst_parse_launch ("curlhttpsrc location=http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_640x360.m4v ! fakesink", NULL);

  /* Start playing */
  gst_element_set_state (pipeline, GST_STATE_PLAYING);

  /* Wait until error or EOS */
  bus = gst_element_get_bus (pipeline);
  msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);

  /* Free resources */
  if (msg != NULL)
    gst_message_unref (msg);
  gst_object_unref (bus);
  gst_element_set_state (pipeline, GST_STATE_NULL);
  gst_object_unref (pipeline);
  return 0;
}
#if 1
gpointer thread_func2(gpointer data) {
  GstElement *pipeline;
  GstBus *bus;
  GstMessage *msg;

  /* Initialize GStreamer */

  /* Build the pipeline */
  pipeline = gst_parse_launch ("curlhttpsrc location=http://download.blender.org/peach/bigbuckbunny_movies/finalscript.rtf ! fakesink", NULL);

  /* Start playing */
  gst_element_set_state (pipeline, GST_STATE_PLAYING);

  /* Wait until error or EOS */
  bus = gst_element_get_bus (pipeline);
  msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);

  /* Free resources */
  if (msg != NULL)
    gst_message_unref (msg);
  gst_object_unref (bus);
  gst_element_set_state (pipeline, GST_STATE_NULL);
  gst_object_unref (pipeline);
  return 0;
}
#endif

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

  GThread *pthread1;
  GThread *pthread2;
  /* Initialize GStreamer */
  gst_init (&argc, &argv);

  pthread1 = g_thread_new("thread1", thread_func1, NULL);
  pthread2 = g_thread_new("thread2", thread_func2, NULL);

  g_thread_join(pthread1);
  g_thread_join(pthread2);

 return 0;
}


