summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDamien Lespiau <damien.lespiau@intel.com>2009-09-05 00:08:20 +0100
committerDamien Lespiau <damien.lespiau@intel.com>2009-09-05 00:23:55 +0100
commitc3f5fd7f51502e886791a1b76574a769a9e38524 (patch)
tree5d8fe1f4f43d7b8f13a02c8f22701ff4b921a191 /tests
parent4162ad998584593af0cff252766b31ea2f1bded8 (diff)
downloadclutter-gst-c3f5fd7f51502e886791a1b76574a769a9e38524.tar.gz
[tests] Add an alpha test
The purpose of this test is to verify that we can now blend a video into a scene using the glColor of underlying actor.
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.am45
-rw-r--r--tests/test-alpha.c194
3 files changed, 222 insertions, 18 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 38db73b..feee60f 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,3 +1,4 @@
+test-alpha
test-rgb-upload
test-start-stop
test-yuv-upload
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ace8bfe..f62de48 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,31 +1,40 @@
NULL = #
-noinst_PROGRAMS = test-yuv-upload \
- test-rgb-upload \
- test-start-stop \
- $(NULL)
+noinst_PROGRAMS = \
+ test-alpha \
+ test-rgb-upload \
+ test-start-stop \
+ test-yuv-upload \
+ $(NULL)
INCLUDES = -I$(top_srcdir) \
$(MAINTAINER_CFLAGS) \
$(NULL)
-test_yuv_upload_SOURCES = test-yuv-upload.c
-test_yuv_upload_CFLAGS = $(CLUTTER_GST_CFLAGS) $(GST_CFLAGS)
-test_yuv_upload_LDFLAGS = \
- $(CLUTTER_GST_LIBS) \
- $(GST_LIBS) \
- $(top_builddir)/clutter-gst/libclutter-gst-@CLUTTER_GST_MAJORMINOR@.la
+test_alpha_SOURCES = test-alpha.c
+test_alpha_CFLAGS = $(CLUTTER_GST_CFLAGS) $(GST_CFLAGS)
+test_alpha_LDFLAGS = \
+ $(CLUTTER_GST_LIBS) \
+ $(GST_LIBS) \
+ $(top_builddir)/clutter-gst/libclutter-gst-@CLUTTER_GST_MAJORMINOR@.la
test_rgb_upload_SOURCES = test-rgb-upload.c
test_rgb_upload_CFLAGS = $(CLUTTER_GST_CFLAGS) $(GST_CFLAGS)
-test_rgb_upload_LDFLAGS = \
- $(CLUTTER_GST_LIBS) \
- $(GST_LIBS) \
- $(top_builddir)/clutter-gst/libclutter-gst-@CLUTTER_GST_MAJORMINOR@.la
+test_rgb_upload_LDFLAGS = \
+ $(CLUTTER_GST_LIBS) \
+ $(GST_LIBS) \
+ $(top_builddir)/clutter-gst/libclutter-gst-@CLUTTER_GST_MAJORMINOR@.la
test_start_stop_SOURCES = test-start-stop.c
test_start_stop_CFLAGS = $(CLUTTER_GST_CFLAGS) $(GST_CFLAGS)
-test_start_stop_LDFLAGS = \
- $(CLUTTER_GST_LIBS) \
- $(GST_LIBS) \
- $(top_builddir)/clutter-gst/libclutter-gst-@CLUTTER_GST_MAJORMINOR@.la
+test_start_stop_LDFLAGS = \
+ $(CLUTTER_GST_LIBS) \
+ $(GST_LIBS) \
+ $(top_builddir)/clutter-gst/libclutter-gst-@CLUTTER_GST_MAJORMINOR@.la
+
+test_yuv_upload_SOURCES = test-yuv-upload.c
+test_yuv_upload_CFLAGS = $(CLUTTER_GST_CFLAGS) $(GST_CFLAGS)
+test_yuv_upload_LDFLAGS = \
+ $(CLUTTER_GST_LIBS) \
+ $(GST_LIBS) \
+ $(top_builddir)/clutter-gst/libclutter-gst-@CLUTTER_GST_MAJORMINOR@.la
diff --git a/tests/test-alpha.c b/tests/test-alpha.c
new file mode 100644
index 0000000..4a9dbc1
--- /dev/null
+++ b/tests/test-alpha.c
@@ -0,0 +1,194 @@
+/*
+ * Clutter-GStreamer.
+ *
+ * GStreamer integration library for Clutter.
+ *
+ * test-alpha.c - Transparent videos.
+ *
+ * Authored by Damien Lespiau <damien.lespiau@intel.com>
+ *
+ * Copyright (C) 2009 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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.
+ */
+
+#include <string.h>
+
+#include <math.h>
+
+#include <glib/gprintf.h>
+#include <clutter-gst/clutter-gst.h>
+
+static gint opt_framerate = 30;
+static gchar *opt_fourcc = "I420";
+
+static GOptionEntry options[] =
+{
+ { "framerate",
+ 'f', 0,
+ G_OPTION_ARG_INT,
+ &opt_framerate,
+ "Number of frames per second",
+ NULL },
+ { "fourcc",
+ 'o', 0,
+ G_OPTION_ARG_STRING,
+ &opt_fourcc,
+ "Fourcc of the wanted YUV format",
+ NULL },
+
+ { NULL }
+};
+
+static guint32
+parse_fourcc (const gchar *fourcc)
+{
+ if (strlen (fourcc) != 4)
+ return 0;
+
+ return GST_STR_FOURCC (fourcc);
+}
+
+void
+size_change (ClutterTexture *texture,
+ gfloat width,
+ gfloat height,
+ gpointer user_data)
+{
+ ClutterActor *stage;
+ gfloat new_x, new_y, new_width, new_height;
+ gfloat stage_width, stage_height;
+
+ stage = clutter_actor_get_stage (CLUTTER_ACTOR (texture));
+ if (stage == NULL)
+ return;
+
+ clutter_actor_get_size (stage, &stage_width, &stage_height);
+
+ new_height = (height * stage_width) / width;
+ if (new_height <= stage_height)
+ {
+ new_width = stage_width;
+
+ new_x = 0;
+ new_y = (stage_height - new_height) / 2;
+ }
+ else
+ {
+ new_width = (width * stage_height) / height;
+ new_height = stage_height;
+
+ new_x = (stage_width - new_width) / 2;
+ new_y = 0;
+ }
+
+ clutter_actor_set_position (CLUTTER_ACTOR (texture), new_x, new_y);
+ clutter_actor_set_size (CLUTTER_ACTOR (texture), new_width, new_height);
+}
+
+int
+main (int argc, char *argv[])
+{
+ GError *error = NULL;
+ gboolean result;
+
+ const ClutterColor stage_color = {128, 0, 192, 255};
+ const ClutterColor rectangle_color = { 96, 0, 0, 255};
+ const ClutterGeometry rectangle_geom = {110, 70, 100, 100};
+ ClutterActor *stage;
+ ClutterActor *texture;
+ ClutterActor *rectangle;
+ ClutterAnimation *animation;
+
+ GstPipeline *pipeline;
+ GstElement *src;
+ GstElement *capsfilter;
+ GstElement *sink;
+ GstCaps *caps;
+
+ if (!g_thread_supported ())
+ g_thread_init (NULL);
+
+ result = clutter_gst_init_with_args (&argc,
+ &argv,
+ " - Test alpha with video textures",
+ options,
+ NULL,
+ &error);
+
+ if (error)
+ {
+ g_print ("%s\n", error->message);
+ g_error_free (error);
+ return EXIT_FAILURE;
+ }
+
+
+ stage = clutter_stage_get_default ();
+ clutter_actor_set_size (stage, 320.0f, 240.0f);
+ clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
+
+ rectangle = clutter_rectangle_new_with_color (&rectangle_color);
+ clutter_actor_set_geometry (rectangle, &rectangle_geom);
+
+ /* We need to set certain props on the target texture currently for
+ * efficient/corrent playback onto the texture (which sucks a bit)
+ */
+ texture = g_object_new (CLUTTER_TYPE_TEXTURE,
+ "sync-size", FALSE,
+ "disable-slicing", TRUE,
+ NULL);
+ clutter_actor_set_opacity (texture, 0);
+
+ g_signal_connect (CLUTTER_TEXTURE (texture),
+ "size-change",
+ G_CALLBACK (size_change), NULL);
+
+ /* Set up pipeline */
+ pipeline = GST_PIPELINE(gst_pipeline_new (NULL));
+
+ src = gst_element_factory_make ("videotestsrc", NULL);
+ g_object_set (G_OBJECT (src), "pattern", 1, NULL);
+ capsfilter = gst_element_factory_make ("capsfilter", NULL);
+ sink = clutter_gst_video_sink_new (CLUTTER_TEXTURE (texture));
+
+ /* make videotestsrc spit the format we want */
+ caps = gst_caps_new_simple ("video/x-raw-yuv",
+ "format", GST_TYPE_FOURCC,
+ parse_fourcc (opt_fourcc),
+ "framerate", GST_TYPE_FRACTION, opt_framerate, 1,
+ NULL);
+ g_object_set (capsfilter, "caps", caps, NULL);
+
+ g_printf ("%s: [caps] %s\n", __FILE__, gst_caps_to_string (caps));
+ gst_bin_add_many (GST_BIN (pipeline), src, capsfilter, sink, NULL);
+ result = gst_element_link_many (src, capsfilter, sink, NULL);
+ if (result == FALSE)
+ g_critical("Could not link elements");
+ gst_element_set_state (GST_ELEMENT(pipeline), GST_STATE_PLAYING);
+
+ clutter_container_add (CLUTTER_CONTAINER (stage), rectangle, texture, NULL);
+ clutter_actor_show_all (stage);
+
+ animation = clutter_actor_animate (texture, CLUTTER_LINEAR, 6000,
+ "opacity", 0xff,
+ NULL);
+ clutter_animation_set_loop (animation, TRUE);
+
+ clutter_main();
+
+ return EXIT_SUCCESS;
+}