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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include <gst/gst.h>
21 #include <gst/controller/gstlfocontrolsource.h>
22 #include <gst/controller/gstdirectcontrolbinding.h>
23
24 #include <stdlib.h>
25
26 static gboolean
on_message(GstBus * bus,GstMessage * message,gpointer user_data)27 on_message (GstBus * bus, GstMessage * message, gpointer user_data)
28 {
29 GMainLoop *loop = (GMainLoop *) user_data;
30
31 switch (GST_MESSAGE_TYPE (message)) {
32 case GST_MESSAGE_ERROR:{
33 GError *err = NULL;
34 gchar *debug = NULL;
35
36 g_warning ("Got ERROR");
37 gst_message_parse_error (message, &err, &debug);
38 g_warning ("%s: %s", err->message, debug);
39 g_main_loop_quit (loop);
40 break;
41 }
42 case GST_MESSAGE_WARNING:{
43 GError *err = NULL;
44 gchar *debug = NULL;
45
46 g_warning ("Got WARNING");
47 gst_message_parse_error (message, &err, &debug);
48 g_warning ("%s: %s", err->message, debug);
49 g_main_loop_quit (loop);
50 break;
51 }
52 case GST_MESSAGE_EOS:
53 g_main_loop_quit (loop);
54 break;
55 default:
56 break;
57 }
58
59 return TRUE;
60 }
61
62 gint
main(gint argc,gchar ** argv)63 main (gint argc, gchar ** argv)
64 {
65 GstElement *pipeline;
66 GstElement *shapewipe;
67 GstControlSource *cs;
68 GMainLoop *loop;
69 GstBus *bus;
70 gchar *pipeline_string;
71 gfloat border = 0.05;
72
73 if (argc < 2) {
74 g_print ("Usage: shapewipe mask.png <border>\n");
75 return -1;
76 }
77
78 gst_init (&argc, &argv);
79
80 if (argc > 2) {
81 border = atof (argv[2]);
82 }
83
84 pipeline_string =
85 g_strdup_printf
86 ("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.",
87 border, argv[1]);
88
89 pipeline = gst_parse_launch (pipeline_string, NULL);
90 g_free (pipeline_string);
91
92 if (pipeline == NULL) {
93 g_print ("Failed to create pipeline\n");
94 return -2;
95 }
96
97 shapewipe = gst_bin_get_by_name (GST_BIN (pipeline), "shape");
98
99 cs = gst_lfo_control_source_new ();
100
101 gst_object_add_control_binding (GST_OBJECT_CAST (shapewipe),
102 gst_direct_control_binding_new (GST_OBJECT_CAST (shapewipe), "position",
103 cs));
104 gst_object_unref (shapewipe);
105
106 g_object_set (cs,
107 "amplitude", 0.5,
108 "offset", 0.5, "frequency", 0.25, "timeshift", 500 * GST_MSECOND, NULL);
109
110 g_object_unref (cs);
111
112 loop = g_main_loop_new (NULL, FALSE);
113
114 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
115 gst_bus_add_signal_watch (bus);
116 g_signal_connect (G_OBJECT (bus), "message", G_CALLBACK (on_message), loop);
117 gst_object_unref (GST_OBJECT (bus));
118
119 if (gst_element_set_state (pipeline,
120 GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
121 g_error ("Failed to go into PLAYING state");
122 return -4;
123 }
124
125 g_main_loop_run (loop);
126
127 gst_element_set_state (pipeline, GST_STATE_NULL);
128
129 g_main_loop_unref (loop);
130
131 gst_object_unref (G_OBJECT (pipeline));
132
133 return 0;
134 }
135