gint
main (gint argc, gchar ** argv)
{
  GstElement *pipeline;
  GstElement *shapewipe;
  GstControlSource *cs;
  GMainLoop *loop;
  GstBus *bus;
  gchar *pipeline_string;
  gfloat border = 0.05;

  if (argc < 2) {
    g_print ("Usage: shapewipe mask.png <border>\n");
    return -1;
  }

  gst_init (&argc, &argv);

  if (argc > 2) {
    border = atof (argv[2]);
  }

  pipeline_string =
      g_strdup_printf
      ("videotestsrc ! video/x-raw,format=(string)AYUV,width=640,height=480 ! shapewipe name=shape border=%f ! videomixer name=mixer ! videoconvert ! autovideosink     filesrc location=%s ! typefind ! decodebin2 ! videoconvert ! videoscale ! queue ! shape.mask_sink    videotestsrc pattern=snow ! video/x-raw,format=(string)AYUV,width=640,height=480 ! queue ! mixer.",
      border, argv[1]);

  pipeline = gst_parse_launch (pipeline_string, NULL);
  g_free (pipeline_string);

  if (pipeline == NULL) {
    g_print ("Failed to create pipeline\n");
    return -2;
  }

  shapewipe = gst_bin_get_by_name (GST_BIN (pipeline), "shape");

  cs = gst_lfo_control_source_new ();

  gst_object_add_control_binding (GST_OBJECT_CAST (shapewipe),
      gst_direct_control_binding_new (GST_OBJECT_CAST (shapewipe), "position",
          cs));

  g_object_set (cs,
      "amplitude", 0.5,
      "offset", 0.5, "frequency", 0.25, "timeshift", 500 * GST_MSECOND, NULL);

  g_object_unref (cs);

  loop = g_main_loop_new (NULL, FALSE);

  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  gst_bus_add_signal_watch (bus);
  g_signal_connect (G_OBJECT (bus), "message", G_CALLBACK (on_message), loop);
  gst_object_unref (GST_OBJECT (bus));

  if (gst_element_set_state (pipeline,
          GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
    g_error ("Failed to go into PLAYING state");
    return -4;
  }

  g_main_loop_run (loop);

  gst_element_set_state (pipeline, GST_STATE_NULL);

  g_main_loop_unref (loop);

  gst_object_unref (G_OBJECT (pipeline));

  return 0;
}
gint
main (gint argc, gchar ** argv)
{
  GstElement *pipeline;
  GstElement *shapewipe;
  GstController *ctrl;
  GstLFOControlSource *csource;
  GValue val = { 0, };
  GMainLoop *loop;
  GstBus *bus;
  gchar *pipeline_string;

  if (argc != 2) {
    g_print ("Usage: shapewipe mask.png\n");
    return -1;
  }

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

  pipeline_string =
      g_strdup_printf
      ("videotestsrc ! video/x-raw-yuv,width=640,height=480 ! shapewipe name=shape border=0.05 ! videomixer name=mixer ! ffmpegcolorspace ! autovideosink     filesrc location=%s ! typefind ! decodebin2 ! ffmpegcolorspace ! videoscale ! queue ! shape.mask_sink    videotestsrc pattern=snow ! video/x-raw-yuv,width=640,height=480 ! queue ! mixer.",
      argv[1]);

  pipeline = gst_parse_launch (pipeline_string, NULL);
  g_free (pipeline_string);

  if (pipeline == NULL) {
    g_print ("Failed to create pipeline\n");
    return -2;
  }

  shapewipe = gst_bin_get_by_name (GST_BIN (pipeline), "shape");

  if (!(ctrl = gst_controller_new (G_OBJECT (shapewipe), "position", NULL))) {
    g_print ("can't control shapewipe element\n");
    return -3;
  }

  csource = gst_lfo_control_source_new ();

  gst_controller_set_control_source (ctrl, "position",
      GST_CONTROL_SOURCE (csource));

  g_value_init (&val, G_TYPE_FLOAT);
  g_value_set_float (&val, 0.5);
  g_object_set (G_OBJECT (csource), "amplitude", &val, NULL);
  g_value_set_float (&val, 0.5);
  g_object_set (G_OBJECT (csource), "offset", &val, NULL);
  g_value_unset (&val);

  g_object_set (G_OBJECT (csource), "frequency", 0.5, NULL);
  g_object_set (G_OBJECT (csource), "timeshift", 500 * GST_MSECOND, NULL);

  g_object_unref (csource);

  loop = g_main_loop_new (NULL, FALSE);

  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  gst_bus_add_signal_watch (bus);
  g_signal_connect (G_OBJECT (bus), "message", G_CALLBACK (on_message), loop);
  gst_object_unref (GST_OBJECT (bus));

  if (gst_element_set_state (pipeline,
          GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
    g_error ("Failed to go into PLAYING state");
    return -4;
  }

  g_main_loop_run (loop);

  gst_element_set_state (pipeline, GST_STATE_NULL);

  g_main_loop_unref (loop);

  g_object_unref (G_OBJECT (ctrl));
  gst_object_unref (G_OBJECT (pipeline));

  return 0;
}