summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDamien Lespiau <damien.lespiau@gmail.com>2009-04-28 02:37:42 +0100
committerDamien Lespiau <damien.lespiau@intel.com>2009-04-28 02:37:42 +0100
commit1861ec15bc83dcb100f2cf90d8dffaf2cc7eb61b (patch)
treeefcfc7f7599d0b093a5a82d43f4f3b2d27d7a9bb /tests
parent3a6f3fb37fce7a217a4870f553a9daf70f16817b (diff)
Add a unit test for RGB frames upload
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.am12
-rw-r--r--tests/test-rgb-upload.c141
3 files changed, 153 insertions, 1 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 2d9cafd..3e817e0 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1 +1,2 @@
test-yuv-upload
+test-rgb-upload
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 723b4dc..ac9eb48 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,4 +1,8 @@
-noinst_PROGRAMS = test-yuv-upload
+NULL =
+
+noinst_PROGRAMS = test-yuv-upload \
+ test-rgb-upload \
+ $(NULL)
INCLUDES = -I$(top_srcdir)/
@@ -9,3 +13,9 @@ test_yuv_upload_LDFLAGS = \
$(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
diff --git a/tests/test-rgb-upload.c b/tests/test-rgb-upload.c
new file mode 100644
index 0000000..3d9db0a
--- /dev/null
+++ b/tests/test-rgb-upload.c
@@ -0,0 +1,141 @@
+#include <string.h>
+
+#include <clutter-gst/clutter-gst.h>
+
+static gint opt_framerate = 25;
+static gint opt_bpp = 24;
+static gint opt_depth = 24;
+
+static GOptionEntry options[] =
+{
+ { "framerate",
+ 'f', 0,
+ G_OPTION_ARG_INT,
+ &opt_framerate,
+ "Number of frames per second (default is 25)",
+ NULL
+ },
+ { "bpp",
+ 'b', 0,
+ G_OPTION_ARG_INT,
+ &opt_bpp,
+ "bits per pixel (default is 32)",
+ NULL
+ },
+ { "depth",
+ 'd', 0,
+ G_OPTION_ARG_INT,
+ &opt_depth,
+ "depth (default is 24)",
+ NULL
+ },
+
+ { NULL }
+};
+
+void
+size_change (ClutterTexture *texture,
+ gint width,
+ gint height,
+ gpointer user_data)
+{
+ gint new_x, new_y, new_width, new_height;
+
+ new_height = ( height * CLUTTER_STAGE_WIDTH() ) / width;
+ if (new_height <= CLUTTER_STAGE_HEIGHT())
+ {
+ new_width = CLUTTER_STAGE_WIDTH();
+
+ new_x = 0;
+ new_y = (CLUTTER_STAGE_HEIGHT() - new_height) / 2;
+ }
+ else
+ {
+ new_width = ( width * CLUTTER_STAGE_HEIGHT() ) / height;
+ new_height = CLUTTER_STAGE_HEIGHT();
+
+ new_x = (CLUTTER_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[])
+{
+ GOptionContext *context;
+ gboolean result;
+ ClutterActor *stage;
+ ClutterActor *texture;
+ GstPipeline *pipeline;
+ GstElement *src;
+ GstElement *capsfilter;
+ GstElement *colorspace;
+ GstElement *sink;
+ GstCaps *caps;
+
+ if (!g_thread_supported ())
+ g_thread_init (NULL);
+
+ context = g_option_context_new (" - test-colorspace options");
+ g_option_context_add_group (context, gst_init_get_option_group ());
+ g_option_context_add_group (context, clutter_get_option_group ());
+ g_option_context_add_main_entries (context, options, NULL);
+ g_option_context_parse (context, &argc, &argv, NULL);
+
+ stage = clutter_stage_get_default ();
+
+ /* 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);
+
+ 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);
+ capsfilter = gst_element_factory_make ("capsfilter", NULL);
+ colorspace = gst_element_factory_make ("ffmpegcolorspace", NULL);
+ sink = clutter_gst_video_sink_new (CLUTTER_TEXTURE (texture));
+
+ g_object_set (G_OBJECT (sink), "use-shaders", FALSE, NULL);
+
+ /* make videotestsrc spit the format we want */
+ caps = gst_caps_new_simple ("video/x-raw-rgb",
+ "bpp", G_TYPE_INT, opt_bpp,
+ "depth", G_TYPE_INT, opt_depth,
+ "framerate", GST_TYPE_FRACTION, opt_framerate, 1,
+#if 0
+ "red_mask", G_TYPE_INT, 0xff000000,
+ "green_mask", G_TYPE_INT, 0x00ff0000,
+ "blue_mask", G_TYPE_INT, 0x0000ff00,
+#endif
+ 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_group_add (CLUTTER_GROUP (stage), texture);
+ clutter_actor_show_all (stage);
+
+ clutter_main();
+
+ return 0;
+}