1b2a69d936f8e9f2309c38fc5d0de55ef997eeaf
[platform/upstream/gst-plugins-good.git] / tests / examples / shapewipe / shapewipe-example.c
1 /* GStreamer
2  * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <gst/gst.h>
21 #include <gst/controller/gstlfocontrolsource.h>
22
23 #include <stdlib.h>
24
25 static gboolean
26 on_message (GstBus * bus, GstMessage * message, gpointer user_data)
27 {
28   GMainLoop *loop = (GMainLoop *) user_data;
29
30   switch (GST_MESSAGE_TYPE (message)) {
31     case GST_MESSAGE_ERROR:{
32       GError *err = NULL;
33       gchar *debug = NULL;
34
35       g_warning ("Got ERROR");
36       gst_message_parse_error (message, &err, &debug);
37       g_warning ("%s: %s", err->message, debug);
38       g_main_loop_quit (loop);
39       break;
40     }
41     case GST_MESSAGE_WARNING:{
42       GError *err = NULL;
43       gchar *debug = NULL;
44
45       g_warning ("Got WARNING");
46       gst_message_parse_error (message, &err, &debug);
47       g_warning ("%s: %s", err->message, debug);
48       g_main_loop_quit (loop);
49       break;
50     }
51     case GST_MESSAGE_EOS:
52       g_main_loop_quit (loop);
53       break;
54     default:
55       break;
56   }
57
58   return TRUE;
59 }
60
61 gint
62 main (gint argc, gchar ** argv)
63 {
64   GstElement *pipeline;
65   GstElement *shapewipe;
66   GstController *ctrl;
67   GstLFOControlSource *csource;
68   GValue val = { 0, };
69   GMainLoop *loop;
70   GstBus *bus;
71   gchar *pipeline_string;
72   gfloat border = 0.05;
73
74   if (argc < 2) {
75     g_print ("Usage: shapewipe mask.png <border>\n");
76     return -1;
77   }
78
79   gst_init (&argc, &argv);
80
81   if (argc > 2) {
82     border = atof (argv[2]);
83   }
84
85   pipeline_string =
86       g_strdup_printf
87       ("videotestsrc ! video/x-raw-yuv,format=(fourcc)AYUV,width=640,height=480 ! shapewipe name=shape border=%f ! videomixer name=mixer ! ffmpegcolorspace ! autovideosink     filesrc location=%s ! typefind ! decodebin2 ! ffmpegcolorspace ! videoscale ! queue ! shape.mask_sink    videotestsrc pattern=snow ! video/x-raw-yuv,format=(fourcc)AYUV,width=640,height=480 ! queue ! mixer.",
88       border, argv[1]);
89
90   pipeline = gst_parse_launch (pipeline_string, NULL);
91   g_free (pipeline_string);
92
93   if (pipeline == NULL) {
94     g_print ("Failed to create pipeline\n");
95     return -2;
96   }
97
98   shapewipe = gst_bin_get_by_name (GST_BIN (pipeline), "shape");
99
100   if (!(ctrl = gst_controller_new (GST_OBJECT (shapewipe), "position", NULL))) {
101     g_print ("can't control shapewipe element\n");
102     return -3;
103   }
104
105   csource = gst_lfo_control_source_new ();
106
107   gst_controller_set_control_source (ctrl, "position",
108       GST_CONTROL_SOURCE (csource));
109
110   g_value_init (&val, G_TYPE_FLOAT);
111   g_value_set_float (&val, 0.5);
112   g_object_set (G_OBJECT (csource), "amplitude", &val, NULL);
113   g_value_set_float (&val, 0.5);
114   g_object_set (G_OBJECT (csource), "offset", &val, NULL);
115   g_value_unset (&val);
116
117   g_object_set (G_OBJECT (csource), "frequency", 0.25, NULL);
118   g_object_set (G_OBJECT (csource), "timeshift", 500 * GST_MSECOND, NULL);
119
120   g_object_unref (csource);
121
122   loop = g_main_loop_new (NULL, FALSE);
123
124   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
125   gst_bus_add_signal_watch (bus);
126   g_signal_connect (G_OBJECT (bus), "message", G_CALLBACK (on_message), loop);
127   gst_object_unref (GST_OBJECT (bus));
128
129   if (gst_element_set_state (pipeline,
130           GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
131     g_error ("Failed to go into PLAYING state");
132     return -4;
133   }
134
135   g_main_loop_run (loop);
136
137   gst_element_set_state (pipeline, GST_STATE_NULL);
138
139   g_main_loop_unref (loop);
140
141   g_object_unref (G_OBJECT (ctrl));
142   gst_object_unref (G_OBJECT (pipeline));
143
144   return 0;
145 }