"Fossies" - the Fresh Open Source Software Archive

Member "gst-plugins-good-1.20.3/tests/check/elements/audiofirfilter.c" (15 Jun 2022, 5292 Bytes) of package /linux/misc/gst-plugins-good-1.20.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "audiofirfilter.c" see the Fossies "Dox" file reference documentation.

    1 /* GStreamer
    2  *
    3  * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
    4  *
    5  * This library is free software; you can redistribute it and/or
    6  * modify it under the terms of the GNU Lesser General Public License
    7  * as published by the Free Software Foundation; either version 2.1 of
    8  * the License, or (at your option) any later version.
    9  * 
   10  * This library is distributed in the hope that it will be useful, but
   11  * WITHOUT ANY WARRANTY; without even the implied warranty of
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13  * Lesser General Public License for more details.
   14  * 
   15  * You should have received a copy of the GNU Lesser General Public
   16  * License along with this library; if not, write to the Free Software
   17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
   18  * 02110-1301 USA
   19  */
   20 
   21 /* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
   22  * with newer GLib versions (>= 2.31.0) */
   23 #define GLIB_DISABLE_DEPRECATION_WARNINGS
   24 
   25 #include <gst/gst.h>
   26 #include <gst/check/gstcheck.h>
   27 
   28 static gboolean have_eos = FALSE;
   29 
   30 static gboolean
   31 on_message (GstBus * bus, GstMessage * message, gpointer user_data)
   32 {
   33   GMainLoop *loop = (GMainLoop *) user_data;
   34 
   35   switch (GST_MESSAGE_TYPE (message)) {
   36     case GST_MESSAGE_ERROR:
   37     case GST_MESSAGE_WARNING:
   38       g_assert_not_reached ();
   39       g_main_loop_quit (loop);
   40       break;
   41 
   42     case GST_MESSAGE_EOS:
   43       have_eos = TRUE;
   44       g_main_loop_quit (loop);
   45       break;
   46     default:
   47       break;
   48   }
   49 
   50   return TRUE;
   51 }
   52 
   53 static void
   54 on_rate_changed (GstElement * element, gint rate, gpointer user_data)
   55 {
   56   GValueArray *va;
   57   GValue v = { 0, };
   58 
   59   fail_unless (rate > 0);
   60 
   61   va = g_value_array_new (6);
   62 
   63   g_value_init (&v, G_TYPE_DOUBLE);
   64   g_value_set_double (&v, 0.0);
   65   g_value_array_append (va, &v);
   66   g_value_reset (&v);
   67   g_value_set_double (&v, 0.0);
   68   g_value_array_append (va, &v);
   69   g_value_reset (&v);
   70   g_value_set_double (&v, 0.0);
   71   g_value_array_append (va, &v);
   72   g_value_reset (&v);
   73   g_value_set_double (&v, 0.0);
   74   g_value_array_append (va, &v);
   75   g_value_reset (&v);
   76   g_value_set_double (&v, 0.0);
   77   g_value_array_append (va, &v);
   78   g_value_reset (&v);
   79   g_value_set_double (&v, 1.0);
   80   g_value_array_append (va, &v);
   81   g_value_reset (&v);
   82 
   83   g_object_set (G_OBJECT (element), "kernel", va, NULL);
   84 
   85   g_value_array_free (va);
   86 }
   87 
   88 static gboolean have_data = FALSE;
   89 
   90 static void
   91 on_handoff (GstElement * object, GstBuffer * buffer, GstPad * pad,
   92     gpointer user_data)
   93 {
   94   if (!have_data) {
   95     GstMapInfo map;
   96     gdouble *data;
   97 
   98     gst_buffer_map (buffer, &map, GST_MAP_READ);
   99     data = (gdouble *) map.data;
  100 
  101     fail_unless (map.size > 5 * sizeof (gdouble));
  102     fail_unless (data[0] == 0.0);
  103     fail_unless (data[1] == 0.0);
  104     fail_unless (data[2] == 0.0);
  105     fail_unless (data[3] == 0.0);
  106     fail_unless (data[4] == 0.0);
  107     fail_unless (data[5] != 0.0);
  108 
  109     gst_buffer_unmap (buffer, &map);
  110     have_data = TRUE;
  111   }
  112 }
  113 
  114 GST_START_TEST (test_pipeline)
  115 {
  116   GstElement *pipeline, *src, *cfilter, *filter, *sink;
  117   GstCaps *caps;
  118   GstBus *bus;
  119   GMainLoop *loop;
  120 
  121   have_data = FALSE;
  122   have_eos = FALSE;
  123 
  124   pipeline = gst_element_factory_make ("pipeline", NULL);
  125   fail_unless (pipeline != NULL);
  126 
  127   src = gst_element_factory_make ("audiotestsrc", NULL);
  128   fail_unless (src != NULL);
  129   g_object_set (G_OBJECT (src), "num-buffers", 1000, NULL);
  130 
  131   cfilter = gst_element_factory_make ("capsfilter", NULL);
  132   fail_unless (cfilter != NULL);
  133 #if G_BYTE_ORDER == G_BIG_ENDIAN
  134   caps = gst_caps_new_simple ("audio/x-raw",
  135       "format", G_TYPE_STRING, "F64BE", NULL);
  136 #else
  137   caps = gst_caps_new_simple ("audio/x-raw",
  138       "format", G_TYPE_STRING, "F64LE", NULL);
  139 #endif
  140   g_object_set (G_OBJECT (cfilter), "caps", caps, NULL);
  141   gst_caps_unref (caps);
  142 
  143   filter = gst_element_factory_make ("audiofirfilter", NULL);
  144   fail_unless (filter != NULL);
  145   g_signal_connect (G_OBJECT (filter), "rate-changed",
  146       G_CALLBACK (on_rate_changed), NULL);
  147 
  148   sink = gst_element_factory_make ("fakesink", NULL);
  149   fail_unless (sink != NULL);
  150   g_object_set (G_OBJECT (sink), "signal-handoffs", TRUE, NULL);
  151   g_signal_connect (G_OBJECT (sink), "handoff", G_CALLBACK (on_handoff), NULL);
  152 
  153   gst_bin_add_many (GST_BIN (pipeline), src, cfilter, filter, sink, NULL);
  154   fail_unless (gst_element_link_many (src, cfilter, filter, sink, NULL));
  155 
  156   loop = g_main_loop_new (NULL, FALSE);
  157 
  158   bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  159   gst_bus_add_signal_watch (bus);
  160   g_signal_connect (G_OBJECT (bus), "message", G_CALLBACK (on_message), loop);
  161 
  162   fail_if (gst_element_set_state (pipeline,
  163           GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE);
  164 
  165   g_main_loop_run (loop);
  166 
  167   fail_unless (have_data);
  168   fail_unless (have_eos);
  169 
  170   fail_unless (gst_element_set_state (pipeline,
  171           GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
  172 
  173   gst_bus_remove_signal_watch (bus);
  174   gst_object_unref (GST_OBJECT (bus));
  175   g_main_loop_unref (loop);
  176   gst_object_unref (pipeline);
  177 }
  178 
  179 GST_END_TEST;
  180 
  181 static Suite *
  182 audiofirfilter_suite (void)
  183 {
  184   Suite *s = suite_create ("audiofirfilter");
  185   TCase *tc_chain = tcase_create ("general");
  186 
  187   suite_add_tcase (s, tc_chain);
  188   tcase_add_test (tc_chain, test_pipeline);
  189 
  190   return s;
  191 }
  192 
  193 GST_CHECK_MAIN (audiofirfilter);