Blame tests/examples/shapewipe/shapewipe-example.c

Packit 8ff292
/* GStreamer
Packit 8ff292
 * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
Packit 8ff292
 *
Packit 8ff292
 * This library is free software; you can redistribute it and/or
Packit 8ff292
 * modify it under the terms of the GNU Library General Public
Packit 8ff292
 * License as published by the Free Software Foundation; either
Packit 8ff292
 * version 2 of the License, or (at your option) any later version.
Packit 8ff292
 *
Packit 8ff292
 * This library is distributed in the hope that it will be useful,
Packit 8ff292
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8ff292
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 8ff292
 * Library General Public License for more details.
Packit 8ff292
 *
Packit 8ff292
 * You should have received a copy of the GNU Library General Public
Packit 8ff292
 * License along with this library; if not, write to the
Packit 8ff292
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 8ff292
 * Boston, MA 02110-1301, USA.
Packit 8ff292
 */
Packit 8ff292
Packit 8ff292
#include <gst/gst.h>
Packit 8ff292
#include <gst/controller/gstlfocontrolsource.h>
Packit 8ff292
#include <gst/controller/gstdirectcontrolbinding.h>
Packit 8ff292
Packit 8ff292
#include <stdlib.h>
Packit 8ff292
Packit 8ff292
static gboolean
Packit 8ff292
on_message (GstBus * bus, GstMessage * message, gpointer user_data)
Packit 8ff292
{
Packit 8ff292
  GMainLoop *loop = (GMainLoop *) user_data;
Packit 8ff292
Packit 8ff292
  switch (GST_MESSAGE_TYPE (message)) {
Packit 8ff292
    case GST_MESSAGE_ERROR:{
Packit 8ff292
      GError *err = NULL;
Packit 8ff292
      gchar *debug = NULL;
Packit 8ff292
Packit 8ff292
      g_warning ("Got ERROR");
Packit 8ff292
      gst_message_parse_error (message, &err, &debug);
Packit 8ff292
      g_warning ("%s: %s", err->message, debug);
Packit 8ff292
      g_main_loop_quit (loop);
Packit 8ff292
      break;
Packit 8ff292
    }
Packit 8ff292
    case GST_MESSAGE_WARNING:{
Packit 8ff292
      GError *err = NULL;
Packit 8ff292
      gchar *debug = NULL;
Packit 8ff292
Packit 8ff292
      g_warning ("Got WARNING");
Packit 8ff292
      gst_message_parse_error (message, &err, &debug);
Packit 8ff292
      g_warning ("%s: %s", err->message, debug);
Packit 8ff292
      g_main_loop_quit (loop);
Packit 8ff292
      break;
Packit 8ff292
    }
Packit 8ff292
    case GST_MESSAGE_EOS:
Packit 8ff292
      g_main_loop_quit (loop);
Packit 8ff292
      break;
Packit 8ff292
    default:
Packit 8ff292
      break;
Packit 8ff292
  }
Packit 8ff292
Packit 8ff292
  return TRUE;
Packit 8ff292
}
Packit 8ff292
Packit 8ff292
gint
Packit 8ff292
main (gint argc, gchar ** argv)
Packit 8ff292
{
Packit 8ff292
  GstElement *pipeline;
Packit 8ff292
  GstElement *shapewipe;
Packit 8ff292
  GstControlSource *cs;
Packit 8ff292
  GMainLoop *loop;
Packit 8ff292
  GstBus *bus;
Packit 8ff292
  gchar *pipeline_string;
Packit 8ff292
  gfloat border = 0.05;
Packit 8ff292
Packit 8ff292
  if (argc < 2) {
Packit 8ff292
    g_print ("Usage: shapewipe mask.png <border>\n");
Packit 8ff292
    return -1;
Packit 8ff292
  }
Packit 8ff292
Packit 8ff292
  gst_init (&argc, &argv);
Packit 8ff292
Packit 8ff292
  if (argc > 2) {
Packit 8ff292
    border = atof (argv[2]);
Packit 8ff292
  }
Packit 8ff292
Packit 8ff292
  pipeline_string =
Packit 8ff292
      g_strdup_printf
Packit 8ff292
      ("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 ! decodebin ! videoconvert ! videoscale ! queue ! shape.mask_sink    videotestsrc pattern=snow ! video/x-raw,format=(string)AYUV,width=640,height=480 ! queue ! mixer.",
Packit 8ff292
      border, argv[1]);
Packit 8ff292
Packit 8ff292
  pipeline = gst_parse_launch (pipeline_string, NULL);
Packit 8ff292
  g_free (pipeline_string);
Packit 8ff292
Packit 8ff292
  if (pipeline == NULL) {
Packit 8ff292
    g_print ("Failed to create pipeline\n");
Packit 8ff292
    return -2;
Packit 8ff292
  }
Packit 8ff292
Packit 8ff292
  shapewipe = gst_bin_get_by_name (GST_BIN (pipeline), "shape");
Packit 8ff292
Packit 8ff292
  cs = gst_lfo_control_source_new ();
Packit 8ff292
Packit 8ff292
  gst_object_add_control_binding (GST_OBJECT_CAST (shapewipe),
Packit 8ff292
      gst_direct_control_binding_new (GST_OBJECT_CAST (shapewipe), "position",
Packit 8ff292
          cs));
Packit 8ff292
  gst_object_unref (shapewipe);
Packit 8ff292
Packit 8ff292
  g_object_set (cs,
Packit 8ff292
      "amplitude", 0.5,
Packit 8ff292
      "offset", 0.5, "frequency", 0.25, "timeshift", 500 * GST_MSECOND, NULL);
Packit 8ff292
Packit 8ff292
  g_object_unref (cs);
Packit 8ff292
Packit 8ff292
  loop = g_main_loop_new (NULL, FALSE);
Packit 8ff292
Packit 8ff292
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
Packit 8ff292
  gst_bus_add_signal_watch (bus);
Packit 8ff292
  g_signal_connect (G_OBJECT (bus), "message", G_CALLBACK (on_message), loop);
Packit 8ff292
  gst_object_unref (GST_OBJECT (bus));
Packit 8ff292
Packit 8ff292
  if (gst_element_set_state (pipeline,
Packit 8ff292
          GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
Packit 8ff292
    g_error ("Failed to go into PLAYING state");
Packit 8ff292
    return -4;
Packit 8ff292
  }
Packit 8ff292
Packit 8ff292
  g_main_loop_run (loop);
Packit 8ff292
Packit 8ff292
  gst_element_set_state (pipeline, GST_STATE_NULL);
Packit 8ff292
Packit 8ff292
  g_main_loop_unref (loop);
Packit 8ff292
Packit 8ff292
  gst_object_unref (G_OBJECT (pipeline));
Packit 8ff292
Packit 8ff292
  return 0;
Packit 8ff292
}