"Fossies" - the Fresh Open Source Software Archive

Member "gst-plugins-good-1.20.3/tests/check/elements/audioecho.c" (15 Jun 2022, 8270 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 "audioecho.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 Library General Public
    7  * License as published by the Free Software Foundation; either
    8  * version 2 of the License, or (at your option) any later version.
    9  *
   10  * This library is distributed in the hope that it will be useful,
   11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13  * Library General Public License for more details.
   14  *
   15  * You should have received a copy of the GNU Library General Public
   16  * License along with this library; if not, write to the
   17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
   18  * Boston, MA 02110-1301, USA.
   19  */
   20 
   21 #include <gst/check/gstcheck.h>
   22 #include <gst/audio/audio.h>
   23 
   24 gboolean have_eos = FALSE;
   25 
   26 /* For ease of programming we use globals to keep refs for our floating
   27  * src and sink pads we create; otherwise we always have to do get_pad,
   28  * get_peer, and then remove references in every test function */
   29 GstPad *mysrcpad, *mysinkpad;
   30 
   31 #define ECHO_CAPS_STRING    \
   32     "audio/x-raw, "               \
   33     "channels = (int) 2, "              \
   34     "channel-mask = (bitmask) 3, "      \
   35     "rate = (int) 100000, "             \
   36     "layout = (string) interleaved, "   \
   37     "format = (string) " GST_AUDIO_NE(F64)
   38 
   39 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
   40     GST_PAD_SINK,
   41     GST_PAD_ALWAYS,
   42     GST_STATIC_CAPS ("audio/x-raw, "
   43         "channels = (int) [ 1, 2 ], "
   44         "rate = (int) [ 1,  MAX ], "
   45         "format = (string) { "
   46         GST_AUDIO_NE (F32) ", " GST_AUDIO_NE (F64) " }"));
   47 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
   48     GST_PAD_SRC,
   49     GST_PAD_ALWAYS,
   50     GST_STATIC_CAPS ("audio/x-raw, "
   51         "channels = (int) [ 1, 2 ], "
   52         "rate = (int) [ 1,  MAX ], "
   53         "format = (string) { "
   54         GST_AUDIO_NE (F32) ", " GST_AUDIO_NE (F64) " }"));
   55 
   56 static GstElement *
   57 setup_echo (void)
   58 {
   59   GstElement *echo;
   60 
   61   GST_DEBUG ("setup_echo");
   62   echo = gst_check_setup_element ("audioecho");
   63   mysrcpad = gst_check_setup_src_pad (echo, &srctemplate);
   64   mysinkpad = gst_check_setup_sink_pad (echo, &sinktemplate);
   65   gst_pad_set_active (mysrcpad, TRUE);
   66   gst_pad_set_active (mysinkpad, TRUE);
   67 
   68   return echo;
   69 }
   70 
   71 static void
   72 cleanup_echo (GstElement * echo)
   73 {
   74   GST_DEBUG ("cleanup_echo");
   75 
   76   g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
   77   g_list_free (buffers);
   78   buffers = NULL;
   79 
   80   gst_pad_set_active (mysrcpad, FALSE);
   81   gst_pad_set_active (mysinkpad, FALSE);
   82   gst_check_teardown_src_pad (echo);
   83   gst_check_teardown_sink_pad (echo);
   84   gst_check_teardown_element (echo);
   85 }
   86 
   87 GST_START_TEST (test_passthrough)
   88 {
   89   GstElement *echo;
   90   GstBuffer *inbuffer, *outbuffer;
   91   GstCaps *caps;
   92   gdouble in[] = { 1.0, -1.0, 0.0, 0.5, -0.5, 0.0 };
   93   gdouble res[6];
   94 
   95   echo = setup_echo ();
   96   g_object_set (G_OBJECT (echo), "delay", (GstClockTime) 1, "intensity", 0.0,
   97       "feedback", 0.0, NULL);
   98   fail_unless (gst_element_set_state (echo,
   99           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
  100       "could not set to playing");
  101 
  102   caps = gst_caps_from_string (ECHO_CAPS_STRING);
  103   gst_check_setup_events (mysrcpad, echo, caps, GST_FORMAT_TIME);
  104   gst_caps_unref (caps);
  105 
  106   inbuffer =
  107       gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, in, sizeof (in), 0,
  108       sizeof (in), NULL, NULL);
  109   fail_unless (gst_buffer_memcmp (inbuffer, 0, in, sizeof (in)) == 0);
  110   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
  111 
  112   /* pushing gives away my reference ... */
  113   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
  114   /* ... but it ends up being collected on the global buffer list */
  115   fail_unless_equals_int (g_list_length (buffers), 1);
  116   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
  117 
  118   fail_unless (gst_buffer_extract (outbuffer, 0, res,
  119           sizeof (res)) == sizeof (res));
  120   GST_INFO
  121       ("expected %+lf %+lf %+lf %+lf %+lf %+lf real %+lf %+lf %+lf %+lf %+lf %+lf",
  122       in[0], in[1], in[2], in[3], in[4], in[5], res[0], res[1], res[2], res[3],
  123       res[4], res[5]);
  124   fail_unless (gst_buffer_memcmp (outbuffer, 0, in, sizeof (in)) == 0);
  125 
  126   /* cleanup */
  127   cleanup_echo (echo);
  128 }
  129 
  130 GST_END_TEST;
  131 
  132 GST_START_TEST (test_echo)
  133 {
  134   GstElement *echo;
  135   GstBuffer *inbuffer, *outbuffer;
  136   GstCaps *caps;
  137   gdouble in[] = { 1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, };
  138   gdouble out[] = { 1.0, -1.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0, 0.0, 0.0 };
  139   gdouble res[10];
  140 
  141   echo = setup_echo ();
  142   g_object_set (G_OBJECT (echo), "delay", (GstClockTime) 20000, "intensity",
  143       1.0, "feedback", 0.0, NULL);
  144   fail_unless (gst_element_set_state (echo,
  145           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
  146       "could not set to playing");
  147 
  148   caps = gst_caps_from_string (ECHO_CAPS_STRING);
  149   gst_check_setup_events (mysrcpad, echo, caps, GST_FORMAT_TIME);
  150   gst_caps_unref (caps);
  151 
  152   inbuffer =
  153       gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, in, sizeof (in), 0,
  154       sizeof (in), NULL, NULL);
  155   fail_unless (gst_buffer_memcmp (inbuffer, 0, in, sizeof (in)) == 0);
  156   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
  157 
  158   /* pushing gives away my reference ... */
  159   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
  160   /* ... but it ends up being collected on the global buffer list */
  161   fail_unless_equals_int (g_list_length (buffers), 1);
  162   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
  163 
  164   fail_unless (gst_buffer_extract (outbuffer, 0, res,
  165           sizeof (res)) == sizeof (res));
  166   GST_INFO
  167       ("expected %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf real %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf",
  168       out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7], out[8],
  169       out[9], res[0], res[1], res[2], res[3], res[4], res[5], res[6], res[7],
  170       res[8], res[9]);
  171   fail_unless (gst_buffer_memcmp (outbuffer, 0, out, sizeof (out)) == 0);
  172 
  173   /* cleanup */
  174   cleanup_echo (echo);
  175 }
  176 
  177 GST_END_TEST;
  178 
  179 GST_START_TEST (test_feedback)
  180 {
  181   GstElement *echo;
  182   GstBuffer *inbuffer, *outbuffer;
  183   GstCaps *caps;
  184   gdouble in[] = { 1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, };
  185   gdouble out[] = { 1.0, -1.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0, 1.0, -1.0 };
  186   gdouble res[10];
  187 
  188   echo = setup_echo ();
  189   g_object_set (G_OBJECT (echo), "delay", (GstClockTime) 20000, "intensity",
  190       1.0, "feedback", 1.0, NULL);
  191   fail_unless (gst_element_set_state (echo,
  192           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
  193       "could not set to playing");
  194 
  195   caps = gst_caps_from_string (ECHO_CAPS_STRING);
  196   gst_check_setup_events (mysrcpad, echo, caps, GST_FORMAT_TIME);
  197   gst_caps_unref (caps);
  198 
  199   inbuffer =
  200       gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, in, sizeof (in), 0,
  201       sizeof (in), NULL, NULL);
  202   fail_unless (gst_buffer_memcmp (inbuffer, 0, in, sizeof (in)) == 0);
  203   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
  204 
  205   /* pushing gives away my reference ... */
  206   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
  207   /* ... but it ends up being collected on the global buffer list */
  208   fail_unless_equals_int (g_list_length (buffers), 1);
  209   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
  210 
  211   fail_unless (gst_buffer_extract (outbuffer, 0, res,
  212           sizeof (res)) == sizeof (res));
  213   GST_INFO
  214       ("expected %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf real %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf %+lf",
  215       out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7], out[8],
  216       out[9], res[0], res[1], res[2], res[3], res[4], res[5], res[6], res[7],
  217       res[8], res[9]);
  218   fail_unless (gst_buffer_memcmp (outbuffer, 0, out, sizeof (out)) == 0);
  219 
  220   /* cleanup */
  221   cleanup_echo (echo);
  222 }
  223 
  224 GST_END_TEST;
  225 
  226 static Suite *
  227 audioecho_suite (void)
  228 {
  229   Suite *s = suite_create ("audioecho");
  230   TCase *tc_chain = tcase_create ("general");
  231 
  232   suite_add_tcase (s, tc_chain);
  233   tcase_add_test (tc_chain, test_passthrough);
  234   tcase_add_test (tc_chain, test_echo);
  235   tcase_add_test (tc_chain, test_feedback);
  236 
  237   return s;
  238 }
  239 
  240 GST_CHECK_MAIN (audioecho);