2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2003> David Schleef <ds@schleef.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * This file was (probably) generated from gstnavigationtest.c,
23 * gstnavigationtest.c,v 1.7 2003/11/08 02:48:59 dschleef Exp
30 #include <gstnavigationtest.h>
42 static void gst_navigationtest_base_init (gpointer g_class);
43 static void gst_navigationtest_class_init (gpointer g_class,
45 static void gst_navigationtest_init (GTypeInstance * instance,
48 static gboolean gst_navigationtest_handle_src_event (GstPad * pad,
51 static GstStateChangeReturn
52 gst_navigationtest_change_state (GstElement * element,
53 GstStateChange transition);
55 static void gst_navigationtest_planar411 (GstVideofilter * videofilter,
56 void *dest, void *src);
57 static void gst_navigationtest_setup (GstVideofilter * videofilter);
59 static GstVideofilterClass *parent_class; /* NULL */
62 gst_navigationtest_get_type (void)
64 static GType navigationtest_type = 0;
66 if (!navigationtest_type) {
67 static const GTypeInfo navigationtest_info = {
68 sizeof (GstNavigationtestClass),
69 gst_navigationtest_base_init,
71 gst_navigationtest_class_init,
74 sizeof (GstNavigationtest),
76 gst_navigationtest_init,
79 navigationtest_type = g_type_register_static (GST_TYPE_VIDEOFILTER,
80 "GstNavigationtest", &navigationtest_info, 0);
82 return navigationtest_type;
85 static GstVideofilterFormat gst_navigationtest_formats[] = {
86 {"I420", 12, gst_navigationtest_planar411,},
91 gst_navigationtest_base_init (gpointer g_class)
93 static GstElementDetails navigationtest_details =
94 GST_ELEMENT_DETAILS ("Video Filter Template",
96 "Template for a video filter",
97 "David Schleef <ds@schleef.org>");
98 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
99 GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
102 gst_element_class_set_details (element_class, &navigationtest_details);
104 for (i = 0; i < G_N_ELEMENTS (gst_navigationtest_formats); i++) {
105 gst_videofilter_class_add_format (videofilter_class,
106 gst_navigationtest_formats + i);
109 gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
113 gst_navigationtest_class_init (gpointer g_class, gpointer class_data)
115 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
116 GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
118 parent_class = g_type_class_peek_parent (g_class);
120 element_class->change_state = gst_navigationtest_change_state;
122 videofilter_class->setup = gst_navigationtest_setup;
126 gst_navigationtest_init (GTypeInstance * instance, gpointer g_class)
128 GstNavigationtest *navtest = GST_NAVIGATIONTEST (instance);
129 GstVideofilter *videofilter = GST_VIDEOFILTER (navtest);
131 gst_pad_set_event_function (videofilter->srcpad,
132 GST_DEBUG_FUNCPTR (gst_navigationtest_handle_src_event));
139 gst_navigationtest_handle_src_event (GstPad * pad, GstEvent * event)
141 GstNavigationtest *navtest;
144 navtest = GST_NAVIGATIONTEST (GST_PAD_PARENT (pad));
146 switch (GST_EVENT_TYPE (event)) {
147 case GST_EVENT_NAVIGATION:
149 const GstStructure *s = gst_event_get_structure (event);
152 fps_n = gst_value_get_fraction_numerator (
153 (&GST_VIDEOFILTER (navtest)->framerate));
154 fps_d = gst_value_get_fraction_denominator (
155 (&GST_VIDEOFILTER (navtest)->framerate));
157 type = gst_structure_get_string (s, "event");
158 if (g_str_equal (type, "mouse-move")) {
159 gst_structure_get_double (s, "pointer_x", &navtest->x);
160 gst_structure_get_double (s, "pointer_y", &navtest->y);
161 } else if (g_str_equal (type, "mouse-button-press")) {
162 ButtonClick *click = g_new (ButtonClick, 1);
164 gst_structure_get_double (s, "pointer_x", &click->x);
165 gst_structure_get_double (s, "pointer_y", &click->y);
166 click->images_left = (fps_n + fps_d - 1) / fps_d;
171 navtest->clicks = g_slist_prepend (navtest->clicks, click);
172 } else if (g_str_equal (type, "mouse-button-release")) {
173 ButtonClick *click = g_new (ButtonClick, 1);
175 gst_structure_get_double (s, "pointer_x", &click->x);
176 gst_structure_get_double (s, "pointer_y", &click->y);
177 click->images_left = (fps_n + fps_d - 1) / fps_d;
182 navtest->clicks = g_slist_prepend (navtest->clicks, click);
189 return gst_pad_event_default (pad, event);
193 gst_navigationtest_setup (GstVideofilter * videofilter)
195 GstNavigationtest *navigationtest;
197 g_return_if_fail (GST_IS_NAVIGATIONTEST (videofilter));
198 navigationtest = GST_NAVIGATIONTEST (videofilter);
200 /* if any setup needs to be done, do it here */
205 draw_box_planar411 (guint8 * dest, int width, int height, int x, int y,
206 guint8 colory, guint8 coloru, guint8 colorv)
210 if (x < 0 || y < 0 || x >= width || y >= height)
214 x2 = MIN (x + 5, width);
216 y2 = MIN (y + 5, height);
218 for (y = y1; y < y2; y++) {
219 for (x = x1; x < x2; x++) {
220 ((guint8 *) dest)[y * width + x] = colory;
224 dest += height * width;
231 for (y = y1; y < y2; y++) {
232 for (x = x1; x < x2; x++) {
233 ((guint8 *) dest)[y * width + x] = coloru;
237 dest += height * width;
238 for (y = y1; y < y2; y++) {
239 for (x = x1; x < x2; x++) {
240 ((guint8 *) dest)[y * width + x] = colorv;
246 gst_navigationtest_planar411 (GstVideofilter * videofilter,
247 void *dest, void *src)
249 GstNavigationtest *navtest = (GstNavigationtest *) videofilter;
253 g_return_if_fail (GST_IS_NAVIGATIONTEST (videofilter));
255 width = gst_videofilter_get_input_width (videofilter);
256 height = gst_videofilter_get_input_height (videofilter);
258 /* do something interesting here. This simply copies the source
259 * to the destination. */
260 memcpy (dest, src, width * height + (width / 2) * (height / 2) * 2);
262 walk = navtest->clicks;
264 ButtonClick *click = walk->data;
266 walk = g_slist_next (walk);
267 draw_box_planar411 (dest, width, height, rint (click->x),
268 rint (click->y), click->cy, click->cu, click->cv);
269 if (--click->images_left < 1) {
270 navtest->clicks = g_slist_remove (navtest->clicks, click);
274 draw_box_planar411 (dest, width, height, rint (navtest->x),
275 rint (navtest->y), 0, 128, 128);
278 static GstStateChangeReturn
279 gst_navigationtest_change_state (GstElement * element,
280 GstStateChange transition)
282 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
283 GstNavigationtest *navtest = GST_NAVIGATIONTEST (element);
285 /* upwards state changes */
286 switch (transition) {
291 if (GST_ELEMENT_CLASS (parent_class)->change_state)
292 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
294 /* downwards state changes */
295 switch (transition) {
296 case GST_STATE_CHANGE_PAUSED_TO_READY:
298 g_slist_foreach (navtest->clicks, (GFunc) g_free, NULL);
299 g_slist_free (navtest->clicks);
300 navtest->clicks = NULL;
311 plugin_init (GstPlugin * plugin)
313 return gst_element_register (plugin, "navigationtest", GST_RANK_NONE,
314 GST_TYPE_NAVIGATIONTEST);
317 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
320 "Template for a video filter",
321 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)