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

gboolean
print_ts (GstPad *pad, GstEvent *ev, gchar *name)
{
  if (GST_EVENT_TYPE (ev) == GST_EVENT_QOS)
    {
      GstClockTimeDiff diff;

      gst_event_parse_qos (ev, NULL, &diff, NULL);
      g_debug ("qos: %ld %" GST_TIME_FORMAT, diff, GST_TIME_ARGS (diff));
    }

  return TRUE;
}

void
add_probe (GstElement *pipeline, gchar *name)
{
  GstElement *e;
  GstPad *pad;

  e = gst_bin_get_by_name (GST_BIN (pipeline), name);
  pad = gst_element_get_pad (e, "sink");
  gst_pad_add_event_probe (pad, G_CALLBACK (print_ts), name);
  gst_object_unref (e);
  gst_object_unref (pad);
}

int main (int argc, char **argv)
{
  GstElement *pipeline;

  gst_init (&argc, &argv);

  pipeline =  gst_parse_launch("v4l2src device=/dev/video1 ! video/x-raw-yuv, width=320, height=240 ! ffmpegcolorspace ! queue min-threshold-time=1000000000 !  xvimagesink name=sink", NULL);

  add_probe (pipeline, "sink");

  gst_element_set_state (pipeline, GST_STATE_PLAYING);
  sleep (10);
  gst_element_set_state (pipeline, GST_STATE_NULL);

  return 0;
}
