summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim@centricular.net>2006-10-04 20:05:07 +0000
committerTim-Philipp Müller <tim@centricular.net>2006-10-04 20:05:07 +0000
commit425c1eecbffec926ed5dae61491458d85fc38599 (patch)
tree655c8e07c01b47c46739ca64ac505f39c603736b
parent099e9349abfe2bd3e65ff812dfa8095a666016ed (diff)
downloadgst-plugins-bad-425c1eecbffec926ed5dae61491458d85fc38599.tar.gz
gst-plugins-bad-425c1eecbffec926ed5dae61491458d85fc38599.tar.bz2
gst-plugins-bad-425c1eecbffec926ed5dae61491458d85fc38599.zip
tests/icles/: Visual test for videocrop, shows that packed yuv doesn't work right yet. --with-ffmpegcolorspace option...
Original commit message from CVS: * tests/icles/.cvsignore: * tests/icles/Makefile.am: * tests/icles/videocrop-test.c: (quit_mainloop), (tick_cb), (test_with_caps), (video_crop_get_test_caps), (main): Visual test for videocrop, shows that packed yuv doesn't work right yet. --with-ffmpegcolorspace option doesn't work yet for unknown reasons (another basetransform issue?)
-rw-r--r--ChangeLog10
-rw-r--r--tests/icles/.gitignore1
-rw-r--r--tests/icles/Makefile.am7
-rw-r--r--tests/icles/videocrop-test.c316
4 files changed, 333 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 7d314ab7..51c57f5b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2006-10-04 Tim-Philipp Müller <tim at centricular dot net>
+ * tests/icles/.cvsignore:
+ * tests/icles/Makefile.am:
+ * tests/icles/videocrop-test.c: (quit_mainloop), (tick_cb),
+ (test_with_caps), (video_crop_get_test_caps), (main):
+ Visual test for videocrop, shows that packed yuv doesn't work right
+ yet. --with-ffmpegcolorspace option doesn't work yet for unknown
+ reasons (another basetransform issue?)
+
+2006-10-04 Tim-Philipp Müller <tim at centricular dot net>
+
* po/POTFILES.in:
* sys/v4l2/.cvsignore:
Remove more v4l2 stuff, hopefully fixing 'make distcheck' again.
diff --git a/tests/icles/.gitignore b/tests/icles/.gitignore
index 3ee2a656..364303c6 100644
--- a/tests/icles/.gitignore
+++ b/tests/icles/.gitignore
@@ -1,2 +1,3 @@
pitch-test
v4l2src-test
+videocrop-test
diff --git a/tests/icles/Makefile.am b/tests/icles/Makefile.am
index 7fcb5aac..26e0cbc3 100644
--- a/tests/icles/Makefile.am
+++ b/tests/icles/Makefile.am
@@ -11,4 +11,9 @@ else
GST_SOUNDTOUCH_TESTS =
endif
-noinst_PROGRAMS = $(GST_SOUNDTOUCH_TESTS)
+videocrop_test_SOURCES = videocrop-test.c
+videocrop_test_CFLAGS = $(GST_CFLAGS)
+videocrop_test_LDADD = $(GST_LIBS)
+videocrop_test_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+
+noinst_PROGRAMS = $(GST_SOUNDTOUCH_TESTS) videocrop-test
diff --git a/tests/icles/videocrop-test.c b/tests/icles/videocrop-test.c
new file mode 100644
index 00000000..775446be
--- /dev/null
+++ b/tests/icles/videocrop-test.c
@@ -0,0 +1,316 @@
+/* GStreamer interactive test for the videocrop element
+ * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
+ *
+ * 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 <gst/gst.h>
+
+#include <stdlib.h>
+#include <math.h>
+
+GST_DEBUG_CATEGORY_STATIC (videocrop_test_debug);
+#define GST_CAT_DEFAULT videocrop_test_debug
+
+#define OUT_WIDTH 640
+#define OUT_HEIGHT 480
+#define TIME_PER_TEST 10 /* seconds each format is tested */
+#define FRAMERATE 15 /* frames per second */
+
+static gboolean
+quit_mainloop (GMainLoop * loop)
+{
+ g_main_loop_quit (loop);
+
+ return FALSE; /* once is enough, don't call us again */
+}
+
+typedef struct _CropState
+{
+ GstElement *videocrop;
+ guint hcrop;
+ guint vcrop;
+} CropState;
+
+static gboolean
+tick_cb (CropState * state)
+{
+ GST_LOG ("hcrop = %3d, vcrop = %3d", state->vcrop, state->hcrop);
+
+ g_object_set (state->videocrop, "left", state->hcrop,
+ "top", state->vcrop, NULL);
+
+ ++state->vcrop;
+ ++state->hcrop;
+
+ return TRUE; /* call us again */
+}
+
+static void
+test_with_caps (GstElement * videocrop, GstCaps * caps)
+{
+ CropState state;
+ GMainLoop *loop;
+
+ /* caps must be writable, we can't check that here though */
+ g_assert (GST_CAPS_REFCOUNT_VALUE (caps) == 1);
+
+ state.videocrop = videocrop;
+ state.vcrop = 0;
+ state.hcrop = 0;
+
+ loop = g_main_loop_new (NULL, FALSE);
+
+ /* quit test after this time (and do it properly for clarity) */
+ g_timeout_add (TIME_PER_TEST * 1000, (GSourceFunc) quit_mainloop, loop);
+
+ g_timeout_add_full (G_PRIORITY_HIGH, 1000 / FRAMERATE,
+ (GSourceFunc) tick_cb, &state, NULL);
+
+ g_main_loop_run (loop);
+ g_main_loop_unref (loop);
+}
+
+/* return a list of caps where we only need to set
+ * width and height to get fixed caps */
+static GList *
+video_crop_get_test_caps (GstElement * videocrop)
+{
+ const GstCaps *allowed_caps;
+ GstPad *srcpad;
+ GList *list = NULL;
+ guint i;
+
+ srcpad = gst_element_get_pad (videocrop, "src");
+ g_assert (srcpad != NULL);
+ allowed_caps = gst_pad_get_pad_template_caps (srcpad);
+ g_assert (allowed_caps != NULL);
+
+ for (i = 0; i < gst_caps_get_size (allowed_caps); ++i) {
+ GstStructure *new_structure;
+ GstCaps *single_caps;
+
+ single_caps = gst_caps_new_empty ();
+ new_structure =
+ gst_structure_copy (gst_caps_get_structure (allowed_caps, i));
+ gst_structure_set (new_structure, "framerate", GST_TYPE_FRACTION,
+ FRAMERATE, 1, NULL);
+ gst_structure_remove_field (new_structure, "width");
+ gst_structure_remove_field (new_structure, "height");
+ gst_caps_append_structure (single_caps, new_structure);
+
+ /* should be fixed without width/height */
+ g_assert (gst_caps_is_fixed (single_caps));
+
+ list = g_list_prepend (list, single_caps);
+ }
+
+ gst_object_unref (srcpad);
+
+ return list;
+}
+
+static gchar *opt_videosink_str; /* NULL */
+static gchar *opt_filtercaps_str; /* NULL */
+static gboolean opt_with_ffmpegcolorspace; /* FALSE */
+
+int
+main (int argc, char **argv)
+{
+ static const GOptionEntry test_goptions[] = {
+ {"videosink", '\0', 0, G_OPTION_ARG_STRING, &opt_videosink_str,
+ "videosink to use (default: autovideosink)", NULL},
+ {"caps", '\0', 0, G_OPTION_ARG_STRING, &opt_filtercaps_str,
+ "filter caps to narrow down formats to test", NULL},
+ {"with-ffmpegcolorspace", '\0', 0, G_OPTION_ARG_NONE,
+ &opt_with_ffmpegcolorspace,
+ "whether to add an ffmpegcolorspace element in front of the sink",
+ NULL},
+ {NULL, '\0', 0, 0, NULL, NULL, NULL}
+ };
+ GOptionContext *ctx;
+ GError *opt_err = NULL;
+
+ GstElement *pipeline, *src, *filter1, *crop, *scale, *filter2, *csp, *sink;
+ GMainLoop *loop;
+ GstCaps *filter_caps = NULL;
+ GList *caps_list, *l;
+
+ /* command line option parsing */
+ ctx = g_option_context_new ("");
+ g_option_context_add_group (ctx, gst_init_get_option_group ());
+ g_option_context_add_main_entries (ctx, test_goptions, NULL);
+
+ if (!g_option_context_parse (ctx, &argc, &argv, &opt_err)) {
+ g_error ("Error parsing command line options: %s", opt_err->message);
+ return -1;
+ }
+
+ gst_init (&argc, &argv);
+
+ GST_DEBUG_CATEGORY_INIT (videocrop_test_debug, "videocroptest", 0, "vctest");
+
+ loop = g_main_loop_new (NULL, FALSE);
+
+ pipeline = gst_pipeline_new ("pipeline");
+ src = gst_element_factory_make ("videotestsrc", "videotestsrc");
+ g_assert (src != NULL);
+ filter1 = gst_element_factory_make ("capsfilter", "capsfilter1");
+ g_assert (filter1 != NULL);
+ crop = gst_element_factory_make ("videocrop", "videocrop");
+ g_assert (crop != NULL);
+ scale = gst_element_factory_make ("videoscale", "videoscale");
+ g_assert (scale != NULL);
+ filter2 = gst_element_factory_make ("capsfilter", "capsfilter2");
+ g_assert (filter2 != NULL);
+
+ if (opt_with_ffmpegcolorspace) {
+ g_print ("Adding ffmpegcolorspace\n");
+ csp = gst_element_factory_make ("ffmpegcolorspace", "colorspace");
+ } else {
+ csp = gst_element_factory_make ("identity", "colorspace");
+ }
+ g_assert (csp != NULL);
+
+ if (opt_filtercaps_str) {
+ filter_caps = gst_caps_from_string (opt_filtercaps_str);
+ if (filter_caps == NULL) {
+ g_error ("Invalid filter caps string '%s'", opt_filtercaps_str);
+ } else {
+ g_print ("Using filter caps '%s'\n", opt_filtercaps_str);
+ }
+ }
+
+ if (opt_videosink_str) {
+ g_print ("Trying videosink '%s' ...", opt_videosink_str);
+ sink = gst_element_factory_make (opt_videosink_str, "sink");
+ g_print ("%s\n", (sink) ? "ok" : "element couldn't be created");
+ } else {
+ sink = NULL;
+ }
+
+ if (sink == NULL) {
+ g_print ("Trying videosink '%s' ...", "autovideosink");
+ sink = gst_element_factory_make ("autovideosink", "sink");
+ g_print ("%s\n", (sink) ? "ok" : "element couldn't be created");
+ }
+ if (sink == NULL) {
+ g_print ("Trying videosink '%s' ...", "xvimagesink");
+ sink = gst_element_factory_make ("xvimagesink", "sink");
+ g_print ("%s\n", (sink) ? "ok" : "element couldn't be created");
+ }
+ if (sink == NULL) {
+ g_print ("Trying videosink '%s' ...", "ximagesink");
+ sink = gst_element_factory_make ("ximagesink", "sink");
+ g_print ("%s\n", (sink) ? "ok" : "element couldn't be created");
+ }
+
+ g_assert (sink != NULL);
+
+ gst_bin_add_many (GST_BIN (pipeline), src, filter1, crop, scale, filter2,
+ csp, sink, NULL);
+
+ if (!gst_element_link (src, filter1))
+ g_error ("Failed to link videotestsrc to capsfilter1");
+
+ if (!gst_element_link (filter1, crop))
+ g_error ("Failed to link capsfilter1 to videocrop");
+
+ if (!gst_element_link (crop, scale))
+ g_error ("Failed to link videocrop to videoscale");
+
+ if (!gst_element_link (scale, filter2))
+ g_error ("Failed to link videoscale to capsfilter2");
+
+ if (!gst_element_link (filter2, csp))
+ g_error ("Failed to link capsfilter2 to ffmpegcolorspace");
+
+ if (!gst_element_link (csp, sink))
+ g_error ("Failed to link ffmpegcolorspace to video sink");
+
+ caps_list = video_crop_get_test_caps (crop);
+ for (l = caps_list; l != NULL; l = l->next) {
+ GstStateChangeReturn ret;
+ GstCaps *caps, *out_caps;
+ gboolean skip = FALSE;
+ gchar *s;
+
+ if (filter_caps) {
+ GstCaps *icaps;
+
+ icaps = gst_caps_intersect (filter_caps, GST_CAPS (l->data));
+ skip = gst_caps_is_empty (icaps);
+ gst_caps_unref (icaps);
+ }
+
+ /* this is the size of our window (stays fixed) */
+ out_caps = gst_caps_copy (GST_CAPS (l->data));
+ gst_structure_set (gst_caps_get_structure (out_caps, 0), "width",
+ G_TYPE_INT, OUT_WIDTH, "height", G_TYPE_INT, OUT_HEIGHT, NULL);
+
+ g_object_set (filter2, "caps", out_caps, NULL);
+
+ /* filter1 gets these too to prevent videotestsrc from renegotiating */
+ g_object_set (filter1, "caps", out_caps, NULL);
+ gst_caps_unref (out_caps);
+
+ caps = gst_caps_copy (GST_CAPS (l->data));
+ GST_INFO ("testing format: %" GST_PTR_FORMAT, caps);
+
+ s = gst_caps_to_string (caps);
+
+ if (skip) {
+ g_print ("Skipping format: %s\n", s);
+ g_free (s);
+ continue;
+ }
+
+ g_print ("Format: %s\n", s);
+
+ caps = gst_caps_make_writable (caps);
+
+ /* FIXME: check return values */
+ ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
+ if (ret != GST_STATE_CHANGE_FAILURE) {
+ ret = gst_element_get_state (pipeline, NULL, NULL, -1);
+
+ if (ret != GST_STATE_CHANGE_FAILURE) {
+ test_with_caps (crop, caps);
+ } else {
+ g_print ("Format: %s not supported (failed to go to PLAYING)\n", s);
+ }
+ } else {
+ g_print ("Format: %s not supported\n", s);
+ }
+
+ gst_element_set_state (pipeline, GST_STATE_NULL);
+
+ gst_caps_unref (caps);
+ g_free (s);
+ }
+
+ g_list_foreach (caps_list, (GFunc) gst_caps_unref, NULL);
+ g_list_free (caps_list);
+
+ gst_element_set_state (pipeline, GST_STATE_NULL);
+ gst_object_unref (pipeline);
+
+ return 0;
+}