tests: add resample test
authorWim Taymans <wtaymans@redhat.com>
Thu, 4 Feb 2016 14:22:39 +0000 (15:22 +0100)
committerWim Taymans <wtaymans@redhat.com>
Mon, 28 Mar 2016 11:25:51 +0000 (13:25 +0200)
tests/icles/Makefile.am
tests/icles/test-resample.c [new file with mode: 0644]

index f479bb7..f489cd4 100644 (file)
@@ -88,6 +88,10 @@ test_scale_SOURCES = test-scale.c
 test_scale_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS)
 test_scale_LDADD = $(GST_LIBS) $(LIBM)
 
+test_resample_SOURCES = test-resample.c
+test_resample_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS)
+test_resample_LDADD = $(GST_LIBS) $(LIBM)
+
 test_box_SOURCES = test-box.c
 test_box_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS)
 test_box_LDADD = $(GST_LIBS) $(LIBM)
@@ -98,4 +102,5 @@ test_reverseplay_LDADD = $(GST_LIBS) $(LIBM)
 
 noinst_PROGRAMS = $(X_TESTS) $(PANGO_TESTS) \
        audio-trickplay playbin-text position-formats stress-playbin \
-       test-scale test-box test-effect-switch test-overlay-blending test-reverseplay
+       test-scale test-box test-effect-switch test-overlay-blending test-reverseplay \
+       test-resample
diff --git a/tests/icles/test-resample.c b/tests/icles/test-resample.c
new file mode 100644 (file)
index 0000000..a956125
--- /dev/null
@@ -0,0 +1,123 @@
+/* GStreamer interactive audioresample test
+ * Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
+ *
+ * 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., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include <gst/gst.h>
+
+static GstElement *
+make_pipeline (gint type)
+{
+  GstElement *result;
+  gchar *pstr;
+
+  switch (type) {
+    case 0:
+      pstr = g_strdup_printf ("audiotestsrc ! audio/x-raw,rate=44100 ! "
+          " audioresample ! capsfilter name=filter ! capssetter caps="
+          "audio/x-raw,rate=44100 ! wavenc ! filesink location=test.wav");
+      break;
+    default:
+      return NULL;
+  }
+
+  result = gst_parse_launch_full (pstr, NULL, GST_PARSE_FLAG_NONE, NULL);
+  g_print ("created test %d: \"%s\"\n", type, pstr);
+  g_free (pstr);
+
+  return result;
+}
+
+typedef struct
+{
+  gint rate;
+  GstElement *filter;
+} Data;
+
+static GstPadProbeReturn
+have_probe (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
+{
+  Data *data = user_data;
+  gchar *capsstr;
+  GstCaps *caps;
+
+  g_print ("resample to %d   \r", data->rate);
+
+  capsstr = g_strdup_printf ("audio/x-raw, rate=(int)%d", data->rate);
+  caps = gst_caps_from_string (capsstr);
+  g_free (capsstr);
+  g_object_set (data->filter, "caps", caps, NULL);
+  gst_caps_unref (caps);
+
+  data->rate += 100;
+
+  if (data->rate > 128000)
+    gst_element_post_message (data->filter,
+        gst_message_new_application (GST_OBJECT (data->filter),
+            gst_structure_new_empty ("my-message")));
+
+  return GST_PAD_PROBE_OK;
+}
+
+int
+main (int argc, char **argv)
+{
+  GstElement *pipe;
+  GstMessage *message;
+  GstPad *srcpad;
+  Data data;
+
+  gst_init (&argc, &argv);
+
+  pipe = make_pipeline (0);
+  if (pipe == NULL)
+    return -1;
+
+  data.rate = 1000;
+  data.filter = gst_bin_get_by_name (GST_BIN (pipe), "filter");
+  g_assert (data.filter);
+
+  srcpad = gst_element_get_static_pad (data.filter, "src");
+  gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM, have_probe,
+      &data, NULL);
+  gst_object_unref (srcpad);
+
+  gst_element_set_state (pipe, GST_STATE_PLAYING);
+
+  while (TRUE) {
+    message =
+        gst_bus_poll (GST_ELEMENT_BUS (pipe),
+        GST_MESSAGE_ERROR | GST_MESSAGE_APPLICATION, 50 * GST_MSECOND);
+    if (message) {
+      g_print ("got error           \n");
+
+      gst_message_unref (message);
+      break;
+    }
+  }
+  gst_object_unref (data.filter);
+  gst_element_set_state (pipe, GST_STATE_NULL);
+  gst_object_unref (pipe);
+
+  return 0;
+}