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 /*#define DEBUG_ENABLED */
31 #include <gstnavigationtest.h>
35 /* GstNavigationtest signals and args */
56 static void gst_navigationtest_base_init (gpointer g_class);
57 static void gst_navigationtest_class_init (gpointer g_class,
59 static void gst_navigationtest_init (GTypeInstance * instance,
62 static gboolean gst_navigationtest_handle_src_event (GstPad * pad,
64 static void gst_navigationtest_set_property (GObject * object, guint prop_id,
65 const GValue * value, GParamSpec * pspec);
66 static void gst_navigationtest_get_property (GObject * object, guint prop_id,
67 GValue * value, GParamSpec * pspec);
69 static GstElementStateReturn
70 gst_navigationtest_change_state (GstElement * element);
72 static void gst_navigationtest_planar411 (GstVideofilter * videofilter,
73 void *dest, void *src);
74 static void gst_navigationtest_setup (GstVideofilter * videofilter);
76 static GstVideofilterClass *parent_class = NULL;
79 gst_navigationtest_get_type (void)
81 static GType navigationtest_type = 0;
83 if (!navigationtest_type) {
84 static const GTypeInfo navigationtest_info = {
85 sizeof (GstNavigationtestClass),
86 gst_navigationtest_base_init,
88 gst_navigationtest_class_init,
91 sizeof (GstNavigationtest),
93 gst_navigationtest_init,
96 navigationtest_type = g_type_register_static (GST_TYPE_VIDEOFILTER,
97 "GstNavigationtest", &navigationtest_info, 0);
99 return navigationtest_type;
102 static GstVideofilterFormat gst_navigationtest_formats[] = {
103 {"I420", 12, gst_navigationtest_planar411,},
108 gst_navigationtest_base_init (gpointer g_class)
110 static GstElementDetails navigationtest_details =
111 GST_ELEMENT_DETAILS ("Video Filter Template",
113 "Template for a video filter",
114 "David Schleef <ds@schleef.org>");
115 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
116 GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
119 gst_element_class_set_details (element_class, &navigationtest_details);
121 for (i = 0; i < G_N_ELEMENTS (gst_navigationtest_formats); i++) {
122 gst_videofilter_class_add_format (videofilter_class,
123 gst_navigationtest_formats + i);
126 gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
130 gst_navigationtest_class_init (gpointer g_class, gpointer class_data)
132 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
133 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
134 GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
136 parent_class = g_type_class_peek_parent (g_class);
138 gobject_class->set_property = gst_navigationtest_set_property;
139 gobject_class->get_property = gst_navigationtest_get_property;
141 element_class->change_state = gst_navigationtest_change_state;
143 videofilter_class->setup = gst_navigationtest_setup;
147 gst_navigationtest_init (GTypeInstance * instance, gpointer g_class)
149 GstNavigationtest *navigationtest = GST_NAVIGATIONTEST (instance);
150 GstVideofilter *videofilter;
152 GST_DEBUG ("gst_navigationtest_init");
154 videofilter = GST_VIDEOFILTER (navigationtest);
156 gst_pad_set_event_function (videofilter->srcpad,
157 gst_navigationtest_handle_src_event);
159 navigationtest->x = -1;
160 navigationtest->y = -1;
164 gst_navigationtest_handle_src_event (GstPad * pad, GstEvent * event)
166 GstNavigationtest *navigationtest;
169 navigationtest = GST_NAVIGATIONTEST (gst_pad_get_parent (pad));
171 switch (GST_EVENT_TYPE (event)) {
172 case GST_EVENT_NAVIGATION:
173 type = gst_structure_get_string (event->event_data.structure.structure,
175 if (g_str_equal (type, "mouse-move")) {
176 gst_structure_get_double (event->event_data.structure.structure,
177 "pointer_x", &navigationtest->x);
178 gst_structure_get_double (event->event_data.structure.structure,
179 "pointer_y", &navigationtest->y);
180 } else if (g_str_equal (type, "mouse-button-press")) {
181 ButtonClick *click = g_new (ButtonClick, 1);
183 gst_structure_get_double (event->event_data.structure.structure,
184 "pointer_x", &click->x);
185 gst_structure_get_double (event->event_data.structure.structure,
186 "pointer_y", &click->y);
187 click->images_left = ceil (GST_VIDEOFILTER (navigationtest)->framerate);
192 navigationtest->clicks =
193 g_slist_prepend (navigationtest->clicks, click);
194 } else if (g_str_equal (type, "mouse-button-release")) {
195 ButtonClick *click = g_new (ButtonClick, 1);
197 gst_structure_get_double (event->event_data.structure.structure,
198 "pointer_x", &click->x);
199 gst_structure_get_double (event->event_data.structure.structure,
200 "pointer_y", &click->y);
201 click->images_left = ceil (GST_VIDEOFILTER (navigationtest)->framerate);
206 navigationtest->clicks =
207 g_slist_prepend (navigationtest->clicks, click);
213 return gst_pad_event_default (pad, event);
217 gst_navigationtest_set_property (GObject * object, guint prop_id,
218 const GValue * value, GParamSpec * pspec)
220 GstNavigationtest *src;
222 g_return_if_fail (GST_IS_NAVIGATIONTEST (object));
223 src = GST_NAVIGATIONTEST (object);
225 GST_DEBUG ("gst_navigationtest_set_property");
229 src->method = g_value_get_enum (value);
238 gst_navigationtest_get_property (GObject * object, guint prop_id,
239 GValue * value, GParamSpec * pspec)
241 GstNavigationtest *src;
243 g_return_if_fail (GST_IS_NAVIGATIONTEST (object));
244 src = GST_NAVIGATIONTEST (object);
249 g_value_set_enum (value, src->method);
253 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
259 plugin_init (GstPlugin * plugin)
261 if (!gst_library_load ("gstvideofilter"))
264 return gst_element_register (plugin, "navigationtest", GST_RANK_NONE,
265 GST_TYPE_NAVIGATIONTEST);
268 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
271 "Template for a video filter",
272 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)
274 static void gst_navigationtest_setup (GstVideofilter * videofilter)
276 GstNavigationtest *navigationtest;
278 g_return_if_fail (GST_IS_NAVIGATIONTEST (videofilter));
279 navigationtest = GST_NAVIGATIONTEST (videofilter);
281 /* if any setup needs to be done, do it here */
286 draw_box_planar411 (guint8 * dest, int width, int height, int x, int y,
287 guint8 colory, guint8 coloru, guint8 colorv)
291 if (x < 0 || y < 0 || x >= width || y >= height)
295 x2 = MIN (x + 5, width);
297 y2 = MIN (y + 5, height);
299 for (y = y1; y < y2; y++) {
300 for (x = x1; x < x2; x++) {
301 ((guint8 *) dest)[y * width + x] = colory;
305 dest += height * width;
312 for (y = y1; y < y2; y++) {
313 for (x = x1; x < x2; x++) {
314 ((guint8 *) dest)[y * width + x] = coloru;
318 dest += height * width;
319 for (y = y1; y < y2; y++) {
320 for (x = x1; x < x2; x++) {
321 ((guint8 *) dest)[y * width + x] = colorv;
327 gst_navigationtest_planar411 (GstVideofilter * videofilter,
328 void *dest, void *src)
330 GstNavigationtest *navigationtest;
331 int width = gst_videofilter_get_input_width (videofilter);
332 int height = gst_videofilter_get_input_height (videofilter);
335 g_return_if_fail (GST_IS_NAVIGATIONTEST (videofilter));
336 navigationtest = GST_NAVIGATIONTEST (videofilter);
338 /* do something interesting here. This simply copies the source
339 * to the destination. */
340 memcpy (dest, src, width * height + (width / 2) * (height / 2) * 2);
342 walk = navigationtest->clicks;
344 ButtonClick *click = walk->data;
346 walk = g_slist_next (walk);
347 draw_box_planar411 (dest, width, height, rint (click->x),
348 rint (click->y), click->cy, click->cu, click->cv);
349 if (--click->images_left < 1) {
350 navigationtest->clicks = g_slist_remove (navigationtest->clicks, click);
354 draw_box_planar411 (dest, width, height, rint (navigationtest->x),
355 rint (navigationtest->y), 0, 128, 128);
358 static GstElementStateReturn
359 gst_navigationtest_change_state (GstElement * element)
361 GstNavigationtest *navigation = GST_NAVIGATIONTEST (element);
363 switch (GST_STATE_TRANSITION (element)) {
364 case GST_STATE_PAUSED_TO_READY:
365 while (navigation->clicks) {
366 g_free (navigation->clicks->data);
368 g_slist_remove (navigation->clicks, navigation->clicks->data);
373 if (GST_ELEMENT_CLASS (parent_class)->change_state)
374 return GST_ELEMENT_CLASS (parent_class)->change_state (element);
376 return GST_STATE_SUCCESS;