From 4e55e480e10a8fa02c4631c129f40fc1521fdbb8 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Thu, 1 Dec 2005 14:50:24 +0000 Subject: [PATCH] add stress test for xoverlay from Julien Original commit message from CVS: add stress test for xoverlay from Julien --- ChangeLog | 11 +++ configure.ac | 1 + tests/Makefile.am | 6 +- tests/icles/.gitignore | 1 + tests/icles/Makefile.am | 7 ++ tests/icles/stress-xoverlay.c | 197 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 221 insertions(+), 2 deletions(-) create mode 100644 tests/icles/.gitignore create mode 100644 tests/icles/Makefile.am create mode 100644 tests/icles/stress-xoverlay.c diff --git a/ChangeLog b/ChangeLog index dd56946..ac63cd5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-12-01 Thomas Vander Stichele + + * configure.ac: + * tests/Makefile.am: + * tests/icles/.cvsignore: + * tests/icles/Makefile.am: + * tests/icles/stress-xoverlay.c: (myclock), (open_display), + (close_display), (resize_window), (move_window), (create_window), + (terminate_playback), (pause_playback), (start_playback), (main): + add stress test for xoverlay from Julien + 2005-12-01 Thomas Vander Stichele * docs/libs/tmpl/gstcolorbalance.sgml: diff --git a/configure.ac b/configure.ac index 9be6af8..6d79edc 100644 --- a/configure.ac +++ b/configure.ac @@ -617,6 +617,7 @@ tests/Makefile tests/check/Makefile tests/examples/Makefile tests/examples/seek/Makefile +tests/icles/Makefile docs/Makefile docs/libs/Makefile docs/plugins/Makefile diff --git a/tests/Makefile.am b/tests/Makefile.am index c8105d5..2badd45 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -12,8 +12,10 @@ endif SUBDIRS = \ $(SUBDIRS_CHECK) \ - $(SUBDIRS_EXAMPLES) + $(SUBDIRS_EXAMPLES) \ + icles DIST_SUBDIRS = \ check \ - examples + examples \ + icles diff --git a/tests/icles/.gitignore b/tests/icles/.gitignore new file mode 100644 index 0000000..103a124 --- /dev/null +++ b/tests/icles/.gitignore @@ -0,0 +1 @@ +stress-xoverlay diff --git a/tests/icles/Makefile.am b/tests/icles/Makefile.am new file mode 100644 index 0000000..4366114 --- /dev/null +++ b/tests/icles/Makefile.am @@ -0,0 +1,7 @@ +noinst_PROGRAMS = stress-xoverlay + +stress_xoverlay_SOURCES = stress-xoverlay.c +stress_xoverlay_CFLAGS = $(GST_CFLAGS) $(X_CFLAGS) +stress_xoverlay_LDFLAGS = $(GST_LIBS) $(X_LIBS) +stress_xoverlay_LDADD = \ + $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-$(GST_MAJORMINOR).la diff --git a/tests/icles/stress-xoverlay.c b/tests/icles/stress-xoverlay.c new file mode 100644 index 0000000..76c76fa --- /dev/null +++ b/tests/icles/stress-xoverlay.c @@ -0,0 +1,197 @@ +/* GStreamer + * Copyright (C) <2005> Julien Moutte + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include +#include + +#include +#include + +static GMainLoop *loop; + +static Display *disp; +static Window root, win; +static GC gc; +static gint width = 320, height = 240, x = 0, y = 0; +static gint disp_width, disp_height; + +static inline long +myclock () +{ + struct timeval tv; + + gettimeofday (&tv, NULL); + return (tv.tv_sec * 1000 + tv.tv_usec / 1000); +} + +static void +open_display (void) +{ + gint screen_num; + + disp = XOpenDisplay (NULL); + root = DefaultRootWindow (disp); + screen_num = DefaultScreen (disp); + disp_width = DisplayWidth (disp, screen_num); + disp_height = DisplayHeight (disp, screen_num); +} + +static void +close_display (void) +{ + XCloseDisplay (disp); +} + +static gboolean +resize_window (GstPipeline * pipeline) +{ + width = (sin (myclock () / 300.0) * 200) + 640; + height = (sin (myclock () / 300.0) * 200) + 480; + + XResizeWindow (disp, win, width, height); + + XSync (disp, FALSE); + + return TRUE; +} + +static gboolean +move_window (GstPipeline * pipeline) +{ + x += 5; + y = disp_height - height + (sin (myclock () / 300.0) * height); + if (x > disp_width) + x = 0; + + XMoveWindow (disp, win, x, y); + + XSync (disp, FALSE); + + return TRUE; +} + +static GstBusSyncReply +create_window (GstBus * bus, GstMessage * message, GstPipeline * pipeline) +{ + XGCValues values; + const GstStructure *s; + + s = gst_message_get_structure (message); + if (!gst_structure_has_name (s, "prepare-xwindow-id")) { + return GST_BUS_PASS; + } + + g_print ("Creating our own window\n"); + + win = XCreateSimpleWindow (disp, root, 0, 0, width, height, 0, 0, 0); + + XSetWindowBackgroundPixmap (disp, win, None); + + gc = XCreateGC (disp, win, 0, &values); + + XMapRaised (disp, win); + + XSync (disp, FALSE); + + gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)), win); + + g_timeout_add (50, (GSourceFunc) resize_window, pipeline); + g_timeout_add (50, (GSourceFunc) move_window, pipeline); + + return GST_BUS_DROP; +} + +#if 0 +static gboolean +terminate_playback (GstElement * pipeline) +{ + g_print ("Terminating playback\n"); + g_main_loop_quit (loop); + return FALSE; +} +#endif + +static gboolean +pause_playback (GstElement * pipeline) +{ + g_print ("Pausing playback\n"); + gst_element_set_state (pipeline, GST_STATE_PAUSED); + return FALSE; +} + +static gboolean +start_playback (GstElement * pipeline) +{ + g_print ("Starting playback\n"); + gst_element_set_state (pipeline, GST_STATE_PLAYING); + return FALSE; +} + +int +main (int argc, char **argv) +{ + GstElement *pipeline; + GstBus *bus; + GError *error = NULL; + + gst_init (&argc, &argv); + + if (argc != 2) { + g_print ("Usage: %s \"pipeline description with launch format\"\n", + argv[0]); + g_print ("The pipeline should contain an element implementing XOverlay.\n"); + g_print ("Example: %s \"videotestsrc ! ximagesink\"\n", argv[0]); + return -1; + } + + pipeline = gst_parse_launch (argv[1], &error); + if (error) { + g_print ("Error while parsing pipeline description: %s\n", error->message); + return -1; + } + + loop = g_main_loop_new (NULL, FALSE); + + open_display (); + + bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); + gst_bus_set_sync_handler (bus, (GstBusSyncHandler) create_window, pipeline); + + gst_element_set_state (pipeline, GST_STATE_PLAYING); + + /* We want to get out after */ + //g_timeout_add (500000, (GSourceFunc) terminate_playback, pipeline); + g_timeout_add (10000, (GSourceFunc) pause_playback, pipeline); + g_timeout_add (20000, (GSourceFunc) start_playback, pipeline); + + g_main_loop_run (loop); + + close_display (); + + g_main_loop_unref (loop); + + return 0; +} -- 2.7.4