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

int main(int argc, char *argv[]) 
{
  GstElement *pipeline;
  GstBus *bus;
  GstMessage *msg;

  const gchar *nano_str;
  guint major, minor, micro, nano;


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

  gst_version (&major, &minor, &micro, &nano);

  printf ("GStreamer Version: %d.%d.%d\n",major, minor, micro);


  /* Build the pipeline */
  //pipeline = gst_parse_launch ("playbin uri=https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm", NULL);
  //pipeline = gst_parse_launch ("playbin uri=rtsp://admin:jenex#2018@192.168.1.108:554 video-sink=waylandsink",NULL);
  pipeline = gst_parse_launch ("playbin uri="rtsp://888888:888888@192.168.1.5:554/cam/realmonitor?channel=1&subtype=1 --live --fps 25" video-sink=waylandsink",NULL);
  //pipeline = gst_parse_launch ("playbin uri=rtsp://admin:admin@192.168.1.3:554 video-sink=waylandsink",NULL);

  
  //pipeline = gst_parse_launch ("rtspsrc location=rtsp://admin:admin@192.168.1.2:554 latency=0 ! decodebin ! videoconvert ! appsink ", NULL);
  //pipeline = gst_parse_launch ("rtspsrc location=rtsp://admin:jenex#2018@192.168.1.108:554 latency=0 ! decodebin ! videoconvert ! appsink ", NULL);


  /* Start playing */
  //gst_element_set_state (pipeline, GST_STATE_PAUSED);
  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;
}

