"Fossies" - the Fresh Open Source Software Archive

Member "gst-plugins-good-1.20.3/tests/check/elements/audioinvert.c" (15 Jun 2022, 9122 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 "audioinvert.c" see the Fossies "Dox" file reference documentation.

    1 /* GStreamer
    2  *
    3  * unit test for audioinvert
    4  *
    5  * Copyright (C) 2007 Sebastian Dröge <slomo@circular-chaos.org>
    6  *
    7  * Greatly based on the audiopanorama unit test
    8  * Copyright (C) 2006 Stefan Kost <ensonic@users.sf.net>
    9  *
   10  * This library is free software; you can redistribute it and/or
   11  * modify it under the terms of the GNU Library General Public
   12  * License as published by the Free Software Foundation; either
   13  * version 2 of the License, or (at your option) any later version.
   14  *
   15  * This library is distributed in the hope that it will be useful,
   16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   18  * Library General Public License for more details.
   19  *
   20  * You should have received a copy of the GNU Library General Public
   21  * License along with this library; if not, write to the
   22  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
   23  * Boston, MA 02110-1301, USA.
   24  */
   25 
   26 #include <gst/audio/audio.h>
   27 #include <gst/base/gstbasetransform.h>
   28 #include <gst/check/gstcheck.h>
   29 
   30 gboolean have_eos = FALSE;
   31 
   32 /* For ease of programming we use globals to keep refs for our floating
   33  * src and sink pads we create; otherwise we always have to do get_pad,
   34  * get_peer, and then remove references in every test function */
   35 GstPad *mysrcpad, *mysinkpad;
   36 
   37 
   38 #define INVERT_CAPS_STRING    \
   39     "audio/x-raw, "                             \
   40     "format = (string) "GST_AUDIO_NE(S16)", "   \
   41     "layout = (string) interleaved, "           \
   42     "channels = (int) 1, "                      \
   43     "rate = (int) 44100"
   44 
   45 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
   46     GST_PAD_SINK,
   47     GST_PAD_ALWAYS,
   48     GST_STATIC_CAPS ("audio/x-raw, "
   49         "format = (string) " GST_AUDIO_NE (S16) ", "
   50         "layout = (string) interleaved, "
   51         "channels = (int) 1, " "rate = (int) [ 1,  MAX ]")
   52     );
   53 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
   54     GST_PAD_SRC,
   55     GST_PAD_ALWAYS,
   56     GST_STATIC_CAPS ("audio/x-raw, "
   57         "format = (string) " GST_AUDIO_NE (S16) ", "
   58         "layout = (string) interleaved, "
   59         "channels = (int) 1, " "rate = (int) [ 1,  MAX ]")
   60     );
   61 
   62 static GstElement *
   63 setup_invert (void)
   64 {
   65   GstElement *invert;
   66 
   67   GST_DEBUG ("setup_invert");
   68   invert = gst_check_setup_element ("audioinvert");
   69   mysrcpad = gst_check_setup_src_pad (invert, &srctemplate);
   70   mysinkpad = gst_check_setup_sink_pad (invert, &sinktemplate);
   71   gst_pad_set_active (mysrcpad, TRUE);
   72   gst_pad_set_active (mysinkpad, TRUE);
   73 
   74   return invert;
   75 }
   76 
   77 static void
   78 cleanup_invert (GstElement * invert)
   79 {
   80   GST_DEBUG ("cleanup_invert");
   81 
   82   g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
   83   g_list_free (buffers);
   84   buffers = NULL;
   85 
   86   gst_pad_set_active (mysrcpad, FALSE);
   87   gst_pad_set_active (mysinkpad, FALSE);
   88   gst_check_teardown_src_pad (invert);
   89   gst_check_teardown_sink_pad (invert);
   90   gst_check_teardown_element (invert);
   91 }
   92 
   93 GST_START_TEST (test_passthrough)
   94 {
   95   GstElement *invert;
   96   GstBuffer *inbuffer, *outbuffer;
   97   GstCaps *caps;
   98   gint16 in[4] = { 16384, -256, 128, -512 };
   99   gint16 *res;
  100   GstMapInfo map;
  101 
  102   invert = setup_invert ();
  103   fail_unless (gst_element_set_state (invert,
  104           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
  105       "could not set to playing");
  106 
  107   inbuffer = gst_buffer_new_and_alloc (8);
  108   gst_buffer_fill (inbuffer, 0, in, 8);
  109   fail_unless (gst_buffer_memcmp (inbuffer, 0, in, 8) == 0);
  110   caps = gst_caps_from_string (INVERT_CAPS_STRING);
  111   gst_check_setup_events (mysrcpad, invert, caps, GST_FORMAT_TIME);
  112   gst_caps_unref (caps);
  113   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
  114 
  115   /* pushing gives away my reference ... */
  116   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
  117   /* ... but it ends up being collected on the global buffer list */
  118   fail_unless_equals_int (g_list_length (buffers), 1);
  119   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
  120 
  121   gst_buffer_map (outbuffer, &map, GST_MAP_READ);
  122   res = (gint16 *) map.data;
  123   GST_INFO ("expected %+5d %+5d %+5d %+5d real %+5d %+5d %+5d %+5d",
  124       in[0], in[1], in[2], in[3], res[0], res[1], res[2], res[3]);
  125   gst_buffer_unmap (outbuffer, &map);
  126 
  127   fail_unless (gst_buffer_memcmp (outbuffer, 0, in, 8) == 0);
  128 
  129   /* cleanup */
  130   cleanup_invert (invert);
  131 }
  132 
  133 GST_END_TEST;
  134 
  135 GST_START_TEST (test_zero)
  136 {
  137   GstElement *invert;
  138   GstBuffer *inbuffer, *outbuffer;
  139   GstCaps *caps;
  140   gint16 in[4] = { 16384, -256, 128, -512 };
  141   gint16 out[4] = { 0, 0, 0, 0 };
  142   gint16 *res;
  143   GstMapInfo map;
  144 
  145   invert = setup_invert ();
  146   g_object_set (G_OBJECT (invert), "degree", 0.5, NULL);
  147   fail_unless (gst_element_set_state (invert,
  148           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
  149       "could not set to playing");
  150 
  151   inbuffer = gst_buffer_new_and_alloc (8);
  152   gst_buffer_fill (inbuffer, 0, in, 8);
  153   fail_unless (gst_buffer_memcmp (inbuffer, 0, in, 8) == 0);
  154   caps = gst_caps_from_string (INVERT_CAPS_STRING);
  155   gst_check_setup_events (mysrcpad, invert, caps, GST_FORMAT_TIME);
  156   gst_caps_unref (caps);
  157   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
  158 
  159   /* pushing gives away my reference ... */
  160   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
  161   /* ... and puts a new buffer on the global list */
  162   fail_unless_equals_int (g_list_length (buffers), 1);
  163   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
  164 
  165   gst_buffer_map (outbuffer, &map, GST_MAP_READ);
  166   res = (gint16 *) map.data;
  167   GST_INFO ("expected %+5d %+5d %+5d %+5d real %+5d %+5d %+5d %+5d",
  168       out[0], out[1], out[2], out[3], res[0], res[1], res[2], res[3]);
  169   gst_buffer_unmap (outbuffer, &map);
  170 
  171   fail_unless (gst_buffer_memcmp (outbuffer, 0, out, 8) == 0);
  172 
  173   /* cleanup */
  174   cleanup_invert (invert);
  175 }
  176 
  177 GST_END_TEST;
  178 
  179 GST_START_TEST (test_full_inverse)
  180 {
  181   GstElement *invert;
  182   GstBuffer *inbuffer, *outbuffer;
  183   GstCaps *caps;
  184   gint16 in[4] = { 16384, -256, 128, -512 };
  185   gint16 out[4] = { -16385, 255, -129, 511 };
  186   gint16 *res;
  187   GstMapInfo map;
  188 
  189   invert = setup_invert ();
  190   g_object_set (G_OBJECT (invert), "degree", 1.0, NULL);
  191   fail_unless (gst_element_set_state (invert,
  192           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
  193       "could not set to playing");
  194 
  195   inbuffer = gst_buffer_new_and_alloc (8);
  196   gst_buffer_fill (inbuffer, 0, in, 8);
  197   fail_unless (gst_buffer_memcmp (inbuffer, 0, in, 8) == 0);
  198   caps = gst_caps_from_string (INVERT_CAPS_STRING);
  199   gst_check_setup_events (mysrcpad, invert, caps, GST_FORMAT_TIME);
  200   gst_caps_unref (caps);
  201   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
  202 
  203   /* pushing gives away my reference ... */
  204   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
  205   /* ... and puts a new buffer on the global list */
  206   fail_unless_equals_int (g_list_length (buffers), 1);
  207   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
  208 
  209   gst_buffer_map (outbuffer, &map, GST_MAP_READ);
  210   res = (gint16 *) map.data;
  211   GST_INFO ("expected %+5d %+5d %+5d %+5d real %+5d %+5d %+5d %+5d",
  212       out[0], out[1], out[2], out[3], res[0], res[1], res[2], res[3]);
  213   gst_buffer_unmap (outbuffer, &map);
  214 
  215   fail_unless (gst_buffer_memcmp (outbuffer, 0, out, 8) == 0);
  216 
  217   /* cleanup */
  218   cleanup_invert (invert);
  219 }
  220 
  221 GST_END_TEST;
  222 
  223 GST_START_TEST (test_25_inverse)
  224 {
  225   GstElement *invert;
  226   GstBuffer *inbuffer, *outbuffer;
  227   GstCaps *caps;
  228   gint16 in[4] = { 16384, -256, 128, -512 };
  229   gint16 out[4] = { 8191, -128, 63, -256 };
  230   gint16 *res;
  231   GstMapInfo map;
  232 
  233   invert = setup_invert ();
  234   g_object_set (G_OBJECT (invert), "degree", 0.25, NULL);
  235   fail_unless (gst_element_set_state (invert,
  236           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
  237       "could not set to playing");
  238 
  239   inbuffer = gst_buffer_new_and_alloc (8);
  240   gst_buffer_fill (inbuffer, 0, in, 8);
  241   fail_unless (gst_buffer_memcmp (inbuffer, 0, in, 8) == 0);
  242   caps = gst_caps_from_string (INVERT_CAPS_STRING);
  243   gst_check_setup_events (mysrcpad, invert, caps, GST_FORMAT_TIME);
  244   gst_caps_unref (caps);
  245   ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
  246 
  247   /* pushing gives away my reference ... */
  248   fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
  249   /* ... and puts a new buffer on the global list */
  250   fail_unless_equals_int (g_list_length (buffers), 1);
  251   fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
  252 
  253   gst_buffer_map (outbuffer, &map, GST_MAP_READ);
  254   res = (gint16 *) map.data;
  255   GST_INFO ("expected %+5d %+5d %+5d %+5d real %+5d %+5d %+5d %+5d",
  256       out[0], out[1], out[2], out[3], res[0], res[1], res[2], res[3]);
  257   gst_buffer_unmap (outbuffer, &map);
  258 
  259   fail_unless (gst_buffer_memcmp (outbuffer, 0, out, 8) == 0);
  260 
  261   /* cleanup */
  262   cleanup_invert (invert);
  263 }
  264 
  265 GST_END_TEST;
  266 
  267 static Suite *
  268 invert_suite (void)
  269 {
  270   Suite *s = suite_create ("invert");
  271   TCase *tc_chain = tcase_create ("general");
  272 
  273   suite_add_tcase (s, tc_chain);
  274   tcase_add_test (tc_chain, test_passthrough);
  275   tcase_add_test (tc_chain, test_zero);
  276   tcase_add_test (tc_chain, test_full_inverse);
  277   tcase_add_test (tc_chain, test_25_inverse);
  278 
  279   return s;
  280 }
  281 
  282 GST_CHECK_MAIN (invert);