Chris@0: /* Chris@0: ** Copyright (C) 2002-2011 Erik de Castro Lopo Chris@0: ** Chris@0: ** This program is free software; you can redistribute it and/or modify Chris@0: ** it under the terms of the GNU General Public License as published by Chris@0: ** the Free Software Foundation; either version 2 of the License, or Chris@0: ** (at your option) any later version. Chris@0: ** Chris@0: ** This program is distributed in the hope that it will be useful, Chris@0: ** but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: ** GNU General Public License for more details. Chris@0: ** Chris@0: ** You should have received a copy of the GNU General Public License Chris@0: ** along with this program; if not, write to the Free Software Chris@0: ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. Chris@0: */ Chris@0: Chris@0: #include "config.h" Chris@0: Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: Chris@0: #if HAVE_ALARM && HAVE_SIGNAL && HAVE_SIGALRM Chris@0: Chris@0: #include Chris@0: Chris@0: #include Chris@0: Chris@0: #include "util.h" Chris@0: Chris@0: #define SHORT_BUFFER_LEN 512 Chris@0: #define LONG_BUFFER_LEN (1 << 14) Chris@0: Chris@0: typedef struct Chris@0: { double ratio ; Chris@0: int count ; Chris@0: } SRC_PAIR ; Chris@0: Chris@0: static void callback_hang_test (int converter) ; Chris@0: Chris@0: static void alarm_handler (int number) ; Chris@0: static long input_callback (void *cb_data, float **data) ; Chris@0: Chris@0: Chris@0: int Chris@0: main (void) Chris@0: { Chris@0: /* Set up SIGALRM handler. */ Chris@0: signal (SIGALRM, alarm_handler) ; Chris@0: Chris@0: puts ("") ; Chris@0: callback_hang_test (SRC_ZERO_ORDER_HOLD) ; Chris@0: callback_hang_test (SRC_LINEAR) ; Chris@0: callback_hang_test (SRC_SINC_FASTEST) ; Chris@0: puts ("") ; Chris@0: Chris@0: return 0 ; Chris@0: } /* main */ Chris@0: Chris@0: Chris@0: static void Chris@0: callback_hang_test (int converter) Chris@0: { static float output [LONG_BUFFER_LEN] ; Chris@0: static SRC_PAIR pairs [] = Chris@0: { Chris@0: { 1.2, 5 }, { 1.1, 1 }, { 1.0, 1 }, { 3.0, 1 }, { 2.0, 1 }, { 0.3, 1 }, Chris@0: { 1.2, 0 }, { 1.1, 10 }, { 1.0, 1 } Chris@0: } ; Chris@0: Chris@0: Chris@0: SRC_STATE *src_state ; Chris@0: Chris@0: double src_ratio = 1.0 ; Chris@0: int k, error ; Chris@0: Chris@0: printf ("\tcallback_hang_test (%-28s) ....... ", src_get_name (converter)) ; Chris@0: fflush (stdout) ; Chris@0: Chris@0: /* Perform sample rate conversion. */ Chris@0: src_state = src_callback_new (input_callback, converter, 1, &error, NULL) ; Chris@0: if (src_state == NULL) Chris@0: { printf ("\n\nLine %d : src_callback_new () failed : %s\n\n", __LINE__, src_strerror (error)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: for (k = 0 ; k < ARRAY_LEN (pairs) ; k++) Chris@0: { alarm (1) ; Chris@0: src_ratio = pairs [k].ratio ; Chris@0: src_callback_read (src_state, src_ratio, pairs [k].count, output) ; Chris@0: } ; Chris@0: Chris@0: src_state = src_delete (src_state) ; Chris@0: Chris@0: alarm (0) ; Chris@0: puts ("ok") ; Chris@0: Chris@0: return ; Chris@0: } /* callback_hang_test */ Chris@0: Chris@0: static void Chris@0: alarm_handler (int number) Chris@0: { Chris@0: (void) number ; Chris@0: printf ("\n\n Error : Hang inside src_callback_read() detected. Exiting!\n\n") ; Chris@0: exit (1) ; Chris@0: } /* alarm_handler */ Chris@0: Chris@0: static long Chris@0: input_callback (void *cb_data, float **data) Chris@0: { Chris@0: static float buffer [20] ; Chris@0: Chris@0: (void) cb_data ; Chris@0: *data = buffer ; Chris@0: Chris@0: return ARRAY_LEN (buffer) ; Chris@0: } /* input_callback */ Chris@0: Chris@0: #else Chris@0: Chris@0: int Chris@0: main (void) Chris@0: { Chris@0: puts ("\tCan't run this test on this platform.") ; Chris@0: return 0 ; Chris@0: } /* main */ Chris@0: Chris@0: #endif