From 95ae3732a8f40ed04f0e4e545b2d05b0af4684b6 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Mon, 5 Aug 2013 23:27:16 +0800 Subject: [PATCH 01/39] FS-5655 --resolve msvc has so many versions, makes it complicated --- Freeswitch.2010.express.sln | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Freeswitch.2010.express.sln b/Freeswitch.2010.express.sln index 4749470674..6b7c5fde3b 100644 --- a/Freeswitch.2010.express.sln +++ b/Freeswitch.2010.express.sln @@ -38,6 +38,11 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_console", "src\mod\loggers\mod_console\mod_console.2010.vcxproj", "{1C453396-D912-4213-89FD-9B489162B7B5}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_xml_rpc", "src\mod\xml_int\mod_xml_rpc\mod_xml_rpc.2010.vcxproj", "{CBEC7225-0C21-4DA8-978E-1F158F8AD950}" + ProjectSection(ProjectDependencies) = postProject + {9D04A840-CE18-4FF5-A6D3-0A2BB92FF2E6} = {9D04A840-CE18-4FF5-A6D3-0A2BB92FF2E6} + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981} = {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981} + {329A6FA0-0FCC-4435-A950-E670AEFA9838} = {329A6FA0-0FCC-4435-A950-E670AEFA9838} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_rss", "src\mod\applications\mod_rss\mod_rss.2010.vcxproj", "{B69247FA-ECD6-40ED-8E44-5CA6C3BAF9A4}" EndProject @@ -221,6 +226,7 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libspandsp", "libs\spandsp\src\libspandsp.2010.vcxproj", "{1CBB0077-18C5-455F-801C-0A0CE7B0BBF5}" ProjectSection(ProjectDependencies) = postProject {019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1} = {019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1} + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981} = {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libspeex", "libs\speex\win32\VS2008\libspeex\libspeex.vcxproj", "{E972C52F-9E85-4D65-B19C-031E511E9DB4}" @@ -338,6 +344,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gennmtab", "libs\win32\xmlr EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_math_fixed_tables", "libs\spandsp\src\msvc\make_math_fixed_tables.2010.vcxproj", "{9D04A840-CE18-4FF5-A6D3-0A2BB92FF2E6}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "make_cielab_luts", "libs\spandsp\src\msvc\make_cielab_luts.2010.vcxproj", "{85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution All|Win32 = All|Win32 @@ -2067,6 +2075,15 @@ Global {9D04A840-CE18-4FF5-A6D3-0A2BB92FF2E6}.Release|Win32.Build.0 = All|Win32 {9D04A840-CE18-4FF5-A6D3-0A2BB92FF2E6}.Release|x64.ActiveCfg = All|Win32 {9D04A840-CE18-4FF5-A6D3-0A2BB92FF2E6}.Release|x64.Build.0 = All|Win32 + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.All|Win32.ActiveCfg = All|Win32 + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.All|Win32.Build.0 = All|Win32 + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.All|x64.ActiveCfg = All|Win32 + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|Win32.ActiveCfg = All|Win32 + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|Win32.Build.0 = All|Win32 + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|x64.ActiveCfg = All|Win32 + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|Win32.ActiveCfg = All|Win32 + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|Win32.Build.0 = All|Win32 + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|x64.ActiveCfg = All|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 7c744ce1d840e29c5c6001c080f40caa682c7daf Mon Sep 17 00:00:00 2001 From: Steve Underwood Date: Mon, 5 Aug 2013 23:50:28 +0800 Subject: [PATCH 02/39] Added custom allocation functions to spandsp --- libs/spandsp/configure.ac | 3 + libs/spandsp/src/Makefile.am | 2 + libs/spandsp/src/alloc.c | 128 +++++++++++++++++++++++++++++++ libs/spandsp/src/spandsp.h.in | 1 + libs/spandsp/src/spandsp/alloc.h | 63 +++++++++++++++ libs/spandsp/tests/Makefile.am | 4 + libs/spandsp/tests/alloc_tests.c | 78 +++++++++++++++++++ libs/spandsp/tests/v18_tests.c | 16 +++- 8 files changed, 292 insertions(+), 3 deletions(-) create mode 100644 libs/spandsp/src/alloc.c create mode 100644 libs/spandsp/src/spandsp/alloc.h create mode 100644 libs/spandsp/tests/alloc_tests.c diff --git a/libs/spandsp/configure.ac b/libs/spandsp/configure.ac index dacc3ae4ed..8a6158fc80 100644 --- a/libs/spandsp/configure.ac +++ b/libs/spandsp/configure.ac @@ -138,6 +138,7 @@ AC_ARG_ENABLE(avx, [ --enable-avx Enable AVX support]) AC_ARG_ENABLE(avx2, [ --enable-avx2 Enable AVX2 support]) AC_ARG_ENABLE(neon, [ --enable-neon Enable NEON support]) AC_ARG_ENABLE(fixed_point, [ --enable-fixed-point Enable fixed point support]) + # The following is for MSVC, where we may be using a local copy of libtiff, built alongside spandsp AC_ARG_ENABLE(builtin_tiff, [AC_HELP_STRING([--enable-builtin-tiff],[build with builtin libtiff])],[enable_builtin_tiff="$enableval"],[enable_builtin_tiff="no"]) @@ -164,6 +165,8 @@ fi AX_C99_FLEXIBLE_ARRAY AC_CHECK_FUNCS([aligned_alloc]) +AC_CHECK_FUNCS([memalign]) +AC_CHECK_FUNCS([posix_memalign]) AC_CHECK_FUNCS([memmove]) AC_CHECK_FUNCS([memset]) AC_CHECK_FUNCS([select]) diff --git a/libs/spandsp/src/Makefile.am b/libs/spandsp/src/Makefile.am index 3d63ae7274..a794e37fb5 100644 --- a/libs/spandsp/src/Makefile.am +++ b/libs/spandsp/src/Makefile.am @@ -84,6 +84,7 @@ lib_LTLIBRARIES = libspandsp.la libspandsp_la_SOURCES = ademco_contactid.c \ adsi.c \ + alloc.c \ async.c \ at_interpreter.c \ awgn.c \ @@ -178,6 +179,7 @@ libspandsp_la_LDFLAGS = -version-info @SPANDSP_LT_CURRENT@:@SPANDSP_LT_REVISION@ nobase_include_HEADERS = spandsp/ademco_contactid.h \ spandsp/adsi.h \ + spandsp/alloc.h \ spandsp/async.h \ spandsp/arctan2.h \ spandsp/at_interpreter.h \ diff --git a/libs/spandsp/src/alloc.c b/libs/spandsp/src/alloc.c new file mode 100644 index 0000000000..e75c603c9f --- /dev/null +++ b/libs/spandsp/src/alloc.c @@ -0,0 +1,128 @@ +/* + * SpanDSP - a series of DSP components for telephony + * + * alloc.c - memory allocation handling. + * + * Written by Steve Underwood + * + * Copyright (C) 2013 Steve Underwood + * + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1, + * as published by the Free Software Foundation. + * + * This program 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/*! \file */ + +#if defined(HAVE_CONFIG_H) +#include "config.h" +#endif + +#include +#include +#include +#include +#define __USE_ISOC11 +#include +#if defined(HAVE_MALLOC_H) +#include +#endif +#include +#include +#include +#include +#include +#include + +#include "spandsp/telephony.h" +#include "spandsp/alloc.h" + +#if defined(HAVE_POSIX_MEMALIGN) +static void *fake_posix_memalign(size_t alignment, size_t size); +#endif +static void *fake_aligned_alloc(size_t alignment, size_t size); + +span_alloc_t __span_alloc = malloc; +#if defined(HAVE_ALIGNED_ALLOC) +span_aligned_alloc_t __span_aligned_alloc = aligned_alloc; +#elif defined(HAVE_MEMALIGN) +span_aligned_alloc_t __span_aligned_alloc = memalign; +#elif defined(HAVE_POSIX_MEMALIGN) +span_aligned_alloc_t __span_aligned_alloc = fake_posix_memalign; +#else +span_aligned_alloc_t __span_aligned_alloc = fake_aligned_alloc; +#endif +span_realloc_t __span_realloc = realloc; +span_free_t __span_free = free; + +#if defined(HAVE_POSIX_MEMALIGN) +static void *fake_posix_memalign(size_t alignment, size_t size) +{ + void *ptr; + + /* Make posix_memalign look like the more modern aligned_alloc */ + posix_memalign(&ptr, alignment, size); + return ptr; +} +/*- End of function --------------------------------------------------------*/ +#endif + +static void *fake_aligned_alloc(size_t alignment, size_t size) +{ + return NULL; +} +/*- End of function --------------------------------------------------------*/ + +SPAN_DECLARE(void *) span_alloc(size_t size) +{ + return __span_alloc(size); +} +/*- End of function --------------------------------------------------------*/ + +SPAN_DECLARE(void *) span_aligned_alloc(size_t alignment, size_t size) +{ + return __span_aligned_alloc(alignment, size); +} +/*- End of function --------------------------------------------------------*/ + +SPAN_DECLARE(void *) span_realloc(void *ptr, size_t size) +{ + return __span_realloc(ptr, size); +} +/*- End of function --------------------------------------------------------*/ + +SPAN_DECLARE(void) span_free(void *ptr) +{ + __span_free(ptr); +} +/*- End of function --------------------------------------------------------*/ + +SPAN_DECLARE(int) span_mem_allocators(span_alloc_t custom_alloc, + span_aligned_alloc_t custom_aligned_alloc, + span_realloc_t custom_realloc, + span_free_t custom_free) +{ + if (custom_alloc == NULL || custom_realloc == NULL || custom_free == NULL) + return -1; + __span_alloc = custom_alloc; + if (custom_aligned_alloc) + __span_aligned_alloc = custom_aligned_alloc; + else + __span_aligned_alloc = fake_aligned_alloc; + __span_realloc = custom_realloc; + __span_free = custom_free; + return 0; +} +/*- End of function --------------------------------------------------------*/ +/*- End of file ------------------------------------------------------------*/ diff --git a/libs/spandsp/src/spandsp.h.in b/libs/spandsp/src/spandsp.h.in index 2764aa4289..d5a7b44581 100644 --- a/libs/spandsp/src/spandsp.h.in +++ b/libs/spandsp/src/spandsp.h.in @@ -48,6 +48,7 @@ #include #include +#include #include #include #include diff --git a/libs/spandsp/src/spandsp/alloc.h b/libs/spandsp/src/spandsp/alloc.h new file mode 100644 index 0000000000..8511897604 --- /dev/null +++ b/libs/spandsp/src/spandsp/alloc.h @@ -0,0 +1,63 @@ +/* + * SpanDSP - a series of DSP components for telephony + * + * alloc.h - memory allocation handling. + * + * Written by Steve Underwood + * + * Copyright (C) 2013 Steve Underwood + * + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1, + * as published by the Free Software Foundation. + * + * This program 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/*! \file */ + +#if !defined(_SPANDSP_ALLOC_H_) +#define _SPANDSP_ALLOC_H_ + +typedef void *(*span_alloc_t)(size_t size); +typedef void *(*span_aligned_alloc_t)(size_t alignment, size_t size); +typedef void *(*span_realloc_t)(void *ptr, size_t size); +typedef void (*span_free_t)(void *ptr); + +#if defined(__cplusplus) +extern "C" +{ +#endif + +/* Allocate size bytes of memory. */ +SPAN_DECLARE(void *) span_alloc(size_t size); + +/* Allocate size bytes allocated to ALIGNMENT bytes. */ +SPAN_DECLARE(void *) span_aligned_alloc(size_t alignment, size_t size); + +/* Re-allocate the previously allocated block in ptr, making the new block size bytes long. */ +SPAN_DECLARE(void *) span_realloc(void *ptr, size_t size); + +/* Free a block allocated by span_alloc, span_aligned_alloc, or span_realloc. */ +SPAN_DECLARE(void) span_free(void *ptr); + +SPAN_DECLARE(int) span_mem_allocators(span_alloc_t custom_alloc, + span_aligned_alloc_t custom_aligned_alloc, + span_realloc_t custom_realloc, + span_free_t custom_free); + +#if defined(__cplusplus) +} +#endif + +#endif +/*- End of file ------------------------------------------------------------*/ diff --git a/libs/spandsp/tests/Makefile.am b/libs/spandsp/tests/Makefile.am index e35408c3b7..8eda2bb201 100644 --- a/libs/spandsp/tests/Makefile.am +++ b/libs/spandsp/tests/Makefile.am @@ -52,6 +52,7 @@ LIBDIR = -L$(top_builddir)/src noinst_PROGRAMS = ademco_contactid_tests \ adsi_tests \ + alloc_tests \ async_tests \ at_interpreter_tests \ awgn_tests \ @@ -146,6 +147,9 @@ ademco_contactid_tests_LDADD = -L$(top_builddir)/spandsp-sim -lspandsp-sim $(LIB adsi_tests_SOURCES = adsi_tests.c adsi_tests_LDADD = -L$(top_builddir)/spandsp-sim -lspandsp-sim $(LIBDIR) -lspandsp +alloc_tests_SOURCES = alloc_tests.c +alloc_tests_LDADD = $(LIBDIR) -lspandsp + async_tests_SOURCES = async_tests.c async_tests_LDADD = $(LIBDIR) -lspandsp diff --git a/libs/spandsp/tests/alloc_tests.c b/libs/spandsp/tests/alloc_tests.c new file mode 100644 index 0000000000..54dfb1e96d --- /dev/null +++ b/libs/spandsp/tests/alloc_tests.c @@ -0,0 +1,78 @@ +/* + * SpanDSP - a series of DSP components for telephony + * + * alloc_tests.c - memory allocation handling tests. + * + * Written by Steve Underwood + * + * Copyright (C) 2013 Steve Underwood + * + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, as + * published by the Free Software Foundation. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/*! \file */ + +/*! \page alloc_tests_page Memory allocation tests +\section alloc_tests_page_sec_1 What does it do? +???. + +\section alloc_tests_page_sec_2 How does it work? +???. +*/ + +#if defined(HAVE_CONFIG_H) +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "spandsp.h" + +int main(int argc, char *argv[]) +{ + void *a; + void *b; + void *c; + + if (span_mem_allocators(malloc, + memalign, + realloc, + free)) + { + printf("Failed\n"); + exit(2); + } + a = span_alloc(42); + b = span_aligned_alloc(8, 42); + c = span_realloc(NULL, 42); + printf("%p %p %p\n", a, b, c); + span_free(a); + span_free(b); + span_free(c); +} +/*- End of function --------------------------------------------------------*/ +/*- End of file ------------------------------------------------------------*/ diff --git a/libs/spandsp/tests/v18_tests.c b/libs/spandsp/tests/v18_tests.c index 0c12678c80..64a47a1593 100644 --- a/libs/spandsp/tests/v18_tests.c +++ b/libs/spandsp/tests/v18_tests.c @@ -7473,7 +7473,7 @@ static int test_x_01(void) result[0][0] = result[1][0] = '\0'; - v18_put(v18[0], "z", 1); + v18_put(v18[0], "zabcdefghijklmnopq", -1); for (i = 0; i < 10000; i++) { for (j = 0; j < 2; j++) @@ -7518,7 +7518,7 @@ static int test_x_01(void) v18_free(v18[0]); v18_free(v18[1]); ref = "cdefghij"; - printf("Result:\n%s\n", result[0]); + printf("Result:\n%s\n", result[1]); printf("Reference result:\n%s\n", ref); if (unexpected_echo || strcmp(result[1], ref) != 0) return -1; @@ -7864,9 +7864,18 @@ static int test_x_04(void) static void x_05_put_text_msg(void *user_data, const uint8_t *msg, int len) { if (user_data == NULL) + { + /* Gather the received characters, which should be like the transmitted characters, + but with the first three characters missing. */ strcat(result[0], (const char *) msg); + } else + { + /* Receiving a character from the far end should block out its receiver + for a while. If we send a stream of DTMF back, the first few characters + (actually 3 for this particular text string) should be lost. */ v18_put(v18[1], "behknqtwz", 9); + } } /*- End of function --------------------------------------------------------*/ @@ -7920,7 +7929,8 @@ static int test_x_05(void) result[0][0] = result[1][0] = '\0'; - v18_put(v18[0], "e", 1); + /* Sending a character should block out the receiver for a while */ + v18_put(v18[0], "z", 1); for (i = 0; i < 1000; i++) { From d5e4089c22a86ccd08b367d6f43fc28c564e1608 Mon Sep 17 00:00:00 2001 From: Steve Underwood Date: Tue, 6 Aug 2013 00:49:15 +0800 Subject: [PATCH 03/39] Moved a lot of spandsp to the use of custom allocation functions --- libs/spandsp/src/ademco_contactid.c | 9 +++++---- libs/spandsp/src/adsi.c | 9 +++++---- libs/spandsp/src/alloc.c | 12 ++++++------ libs/spandsp/src/async.c | 9 +++++---- libs/spandsp/src/at_interpreter.c | 15 ++++++++------- libs/spandsp/src/awgn.c | 5 +++-- libs/spandsp/src/bell_r2_mf.c | 17 +++++++++-------- libs/spandsp/src/bert.c | 5 +++-- libs/spandsp/src/bitstream.c | 5 +++-- libs/spandsp/src/complex_filters.c | 13 +++++++------ libs/spandsp/src/dtmf.c | 9 +++++---- libs/spandsp/src/echo.c | 21 +++++++++++---------- libs/spandsp/src/fax.c | 5 +++-- libs/spandsp/src/fax_modems.c | 5 +++-- libs/spandsp/src/g711.c | 5 +++-- libs/spandsp/src/g722.c | 9 +++++---- libs/spandsp/src/g726.c | 5 +++-- libs/spandsp/src/gsm0610_encode.c | 5 +++-- libs/spandsp/src/logging.c | 5 +++-- libs/spandsp/src/lpc10_decode.c | 5 +++-- libs/spandsp/src/lpc10_encode.c | 5 +++-- libs/spandsp/src/modem_connect_tones.c | 11 ++++++----- libs/spandsp/src/modem_echo.c | 17 +++++++++-------- libs/spandsp/src/noise.c | 5 +++-- libs/spandsp/src/oki_adpcm.c | 5 +++-- libs/spandsp/src/playout.c | 13 +++++++------ libs/spandsp/src/plc.c | 5 +++-- libs/spandsp/src/power_meter.c | 9 +++++---- libs/spandsp/src/queue.c | 5 +++-- libs/spandsp/src/schedule.c | 7 ++++--- libs/spandsp/src/sig_tone.c | 9 +++++---- libs/spandsp/src/silence_gen.c | 5 +++-- libs/spandsp/src/super_tone_rx.c | 25 +++++++++++++------------ libs/spandsp/src/super_tone_tx.c | 9 +++++---- libs/spandsp/src/swept_tone.c | 5 +++-- libs/spandsp/src/t30_api.c | 25 +++++++++++++------------ libs/spandsp/src/t81_t82_arith_coding.c | 9 +++++---- libs/spandsp/src/t85_decode.c | 23 ++++++++++++----------- libs/spandsp/src/t85_encode.c | 15 ++++++++------- libs/spandsp/src/time_scale.c | 7 ++++--- libs/spandsp/src/timezone.c | 5 +++-- libs/spandsp/src/tone_detect.c | 5 +++-- libs/spandsp/src/tone_generate.c | 9 +++++---- libs/spandsp/src/v42.c | 5 +++-- libs/spandsp/src/v42bis.c | 4 +++- libs/spandsp/src/v8.c | 5 +++-- 46 files changed, 233 insertions(+), 187 deletions(-) diff --git a/libs/spandsp/src/ademco_contactid.c b/libs/spandsp/src/ademco_contactid.c index 6aaf99c382..29d1130b99 100644 --- a/libs/spandsp/src/ademco_contactid.c +++ b/libs/spandsp/src/ademco_contactid.c @@ -46,6 +46,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/logging.h" #include "spandsp/queue.h" @@ -749,7 +750,7 @@ SPAN_DECLARE(ademco_contactid_receiver_state_t *) ademco_contactid_receiver_init { if (s == NULL) { - if ((s = (ademco_contactid_receiver_state_t *) malloc(sizeof (*s))) == NULL) + if ((s = (ademco_contactid_receiver_state_t *) span_alloc(sizeof (*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -776,7 +777,7 @@ SPAN_DECLARE(int) ademco_contactid_receiver_release(ademco_contactid_receiver_st SPAN_DECLARE(int) ademco_contactid_receiver_free(ademco_contactid_receiver_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ @@ -1084,7 +1085,7 @@ SPAN_DECLARE(ademco_contactid_sender_state_t *) ademco_contactid_sender_init(ade { if (s == NULL) { - if ((s = (ademco_contactid_sender_state_t *) malloc(sizeof (*s))) == NULL) + if ((s = (ademco_contactid_sender_state_t *) span_alloc(sizeof (*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -1121,7 +1122,7 @@ SPAN_DECLARE(int) ademco_contactid_sender_release(ademco_contactid_sender_state_ SPAN_DECLARE(int) ademco_contactid_sender_free(ademco_contactid_sender_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/adsi.c b/libs/spandsp/src/adsi.c index df327bf3c5..24e87d65ec 100644 --- a/libs/spandsp/src/adsi.c +++ b/libs/spandsp/src/adsi.c @@ -44,6 +44,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/logging.h" #include "spandsp/queue.h" @@ -426,7 +427,7 @@ SPAN_DECLARE(adsi_rx_state_t *) adsi_rx_init(adsi_rx_state_t *s, { if (s == NULL) { - if ((s = (adsi_rx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (adsi_rx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -465,7 +466,7 @@ SPAN_DECLARE(int) adsi_rx_release(adsi_rx_state_t *s) SPAN_DECLARE(int) adsi_rx_free(adsi_rx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ @@ -658,7 +659,7 @@ SPAN_DECLARE(adsi_tx_state_t *) adsi_tx_init(adsi_tx_state_t *s, int standard) { if (s == NULL) { - if ((s = (adsi_tx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (adsi_tx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -688,7 +689,7 @@ SPAN_DECLARE(int) adsi_tx_release(adsi_tx_state_t *s) SPAN_DECLARE(int) adsi_tx_free(adsi_tx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/alloc.c b/libs/spandsp/src/alloc.c index e75c603c9f..d02291248c 100644 --- a/libs/spandsp/src/alloc.c +++ b/libs/spandsp/src/alloc.c @@ -48,11 +48,6 @@ #include "spandsp/telephony.h" #include "spandsp/alloc.h" -#if defined(HAVE_POSIX_MEMALIGN) -static void *fake_posix_memalign(size_t alignment, size_t size); -#endif -static void *fake_aligned_alloc(size_t alignment, size_t size); - span_alloc_t __span_alloc = malloc; #if defined(HAVE_ALIGNED_ALLOC) span_aligned_alloc_t __span_aligned_alloc = aligned_alloc; @@ -60,13 +55,18 @@ span_aligned_alloc_t __span_aligned_alloc = aligned_alloc; span_aligned_alloc_t __span_aligned_alloc = memalign; #elif defined(HAVE_POSIX_MEMALIGN) span_aligned_alloc_t __span_aligned_alloc = fake_posix_memalign; +static void *fake_posix_memalign(size_t alignment, size_t size); #else span_aligned_alloc_t __span_aligned_alloc = fake_aligned_alloc; #endif span_realloc_t __span_realloc = realloc; span_free_t __span_free = free; -#if defined(HAVE_POSIX_MEMALIGN) +static void *fake_aligned_alloc(size_t alignment, size_t size); + +#if defined(HAVE_ALIGNED_ALLOC) +#elif defined(HAVE_MEMALIGN) +#elif defined(HAVE_POSIX_MEMALIGN) static void *fake_posix_memalign(size_t alignment, size_t size) { void *ptr; diff --git a/libs/spandsp/src/async.c b/libs/spandsp/src/async.c index fb381bb7bc..15c73adcc0 100644 --- a/libs/spandsp/src/async.c +++ b/libs/spandsp/src/async.c @@ -35,6 +35,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/bit_operations.h" #include "spandsp/async.h" @@ -174,7 +175,7 @@ SPAN_DECLARE(async_rx_state_t *) async_rx_init(async_rx_state_t *s, { if (s == NULL) { - if ((s = (async_rx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (async_rx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } s->data_bits = data_bits; @@ -203,7 +204,7 @@ SPAN_DECLARE(int) async_rx_release(async_rx_state_t *s) SPAN_DECLARE(int) async_rx_free(async_rx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ @@ -274,7 +275,7 @@ SPAN_DECLARE(async_tx_state_t *) async_tx_init(async_tx_state_t *s, { if (s == NULL) { - if ((s = (async_tx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (async_tx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } /* We have a use_v14 parameter for completeness, but right now V.14 only @@ -304,7 +305,7 @@ SPAN_DECLARE(int) async_tx_release(async_tx_state_t *s) SPAN_DECLARE(int) async_tx_free(async_tx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/at_interpreter.c b/libs/spandsp/src/at_interpreter.c index 2ecdbb866d..d36532afbd 100644 --- a/libs/spandsp/src/at_interpreter.c +++ b/libs/spandsp/src/at_interpreter.c @@ -46,6 +46,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/queue.h" #include "spandsp/power_meter.h" @@ -379,7 +380,7 @@ SPAN_DECLARE(void) at_reset_call_info(at_state_t *s) for (call_id = s->call_id; call_id; call_id = next) { next = call_id->next; - free(call_id); + span_free(call_id); } s->call_id = NULL; s->rings_indicated = 0; @@ -392,8 +393,8 @@ SPAN_DECLARE(void) at_set_call_info(at_state_t *s, char const *id, char const *v at_call_id_t *new_call_id; at_call_id_t *call_id; - /* TODO: We should really not merely ignore a failure to malloc */ - if ((new_call_id = (at_call_id_t *) malloc(sizeof(*new_call_id))) == NULL) + /* TODO: We should really not merely ignore a failure to allocate */ + if ((new_call_id = (at_call_id_t *) span_alloc(sizeof(*new_call_id))) == NULL) return; call_id = s->call_id; /* If these strdups fail its pretty harmless. We just appear to not @@ -752,7 +753,7 @@ static int parse_string_out(at_state_t *s, const char **t, char **target, const default: /* Set value */ if (*target) - free(*target); + span_free(*target); /* If this strdup fails, it should be harmless */ *target = strdup(*t); break; @@ -5590,7 +5591,7 @@ SPAN_DECLARE(at_state_t *) at_init(at_state_t *s, { if (s == NULL) { - if ((s = (at_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (at_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, '\0', sizeof(*s)); @@ -5615,7 +5616,7 @@ SPAN_DECLARE(int) at_release(at_state_t *s) { at_reset_call_info(s); if (s->local_id) - free(s->local_id); + span_free(s->local_id); return 0; } /*- End of function --------------------------------------------------------*/ @@ -5625,7 +5626,7 @@ SPAN_DECLARE(int) at_free(at_state_t *s) int ret; ret = at_release(s); - free(s); + span_free(s); return ret; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/awgn.c b/libs/spandsp/src/awgn.c index 582959cc93..fa33b1b4c5 100644 --- a/libs/spandsp/src/awgn.c +++ b/libs/spandsp/src/awgn.c @@ -55,6 +55,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/saturated.h" #include "spandsp/awgn.h" @@ -100,7 +101,7 @@ SPAN_DECLARE(awgn_state_t *) awgn_init_dbov(awgn_state_t *s, int idum, float lev if (s == NULL) { - if ((s = (awgn_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (awgn_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } if (idum < 0) @@ -140,7 +141,7 @@ SPAN_DECLARE(int) awgn_release(awgn_state_t *s) SPAN_DECLARE(int) awgn_free(awgn_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/bell_r2_mf.c b/libs/spandsp/src/bell_r2_mf.c index dba407cddd..493f766f9c 100644 --- a/libs/spandsp/src/bell_r2_mf.c +++ b/libs/spandsp/src/bell_r2_mf.c @@ -43,6 +43,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/fast_convert.h" #include "spandsp/queue.h" @@ -325,7 +326,7 @@ SPAN_DECLARE(bell_mf_tx_state_t *) bell_mf_tx_init(bell_mf_tx_state_t *s) { if (s == NULL) { - if ((s = (bell_mf_tx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (bell_mf_tx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -348,7 +349,7 @@ SPAN_DECLARE(int) bell_mf_tx_release(bell_mf_tx_state_t *s) SPAN_DECLARE(int) bell_mf_tx_free(bell_mf_tx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ @@ -397,7 +398,7 @@ SPAN_DECLARE(r2_mf_tx_state_t *) r2_mf_tx_init(r2_mf_tx_state_t *s, int fwd) if (s == NULL) { - if ((s = (r2_mf_tx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (r2_mf_tx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -451,7 +452,7 @@ SPAN_DECLARE(int) r2_mf_tx_release(r2_mf_tx_state_t *s) SPAN_DECLARE(int) r2_mf_tx_free(r2_mf_tx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ @@ -633,7 +634,7 @@ SPAN_DECLARE(bell_mf_rx_state_t *) bell_mf_rx_init(bell_mf_rx_state_t *s, if (s == NULL) { - if ((s = (bell_mf_rx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (bell_mf_rx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -671,7 +672,7 @@ SPAN_DECLARE(int) bell_mf_rx_release(bell_mf_rx_state_t *s) SPAN_DECLARE(int) bell_mf_rx_free(bell_mf_rx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ @@ -813,7 +814,7 @@ SPAN_DECLARE(r2_mf_rx_state_t *) r2_mf_rx_init(r2_mf_rx_state_t *s, if (s == NULL) { - if ((s = (r2_mf_rx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (r2_mf_rx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -855,7 +856,7 @@ SPAN_DECLARE(int) r2_mf_rx_release(r2_mf_rx_state_t *s) SPAN_DECLARE(int) r2_mf_rx_free(r2_mf_rx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/bert.c b/libs/spandsp/src/bert.c index a8ad5ad6b7..a4081f66d1 100644 --- a/libs/spandsp/src/bert.c +++ b/libs/spandsp/src/bert.c @@ -35,6 +35,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/async.h" #include "spandsp/bert.h" @@ -350,7 +351,7 @@ SPAN_DECLARE(bert_state_t *) bert_init(bert_state_t *s, int limit, int pattern, if (s == NULL) { - if ((s = (bert_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (bert_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -503,7 +504,7 @@ SPAN_DECLARE(int) bert_release(bert_state_t *s) SPAN_DECLARE(int) bert_free(bert_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/bitstream.c b/libs/spandsp/src/bitstream.c index 9a8c0bc9dd..f3da9c4d0b 100644 --- a/libs/spandsp/src/bitstream.c +++ b/libs/spandsp/src/bitstream.c @@ -35,6 +35,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/bitstream.h" #include "spandsp/private/bitstream.h" @@ -132,7 +133,7 @@ SPAN_DECLARE(bitstream_state_t *) bitstream_init(bitstream_state_t *s, int lsb_f { if (s == NULL) { - if ((s = (bitstream_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (bitstream_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } s->bitstream = 0; @@ -151,7 +152,7 @@ SPAN_DECLARE(int) bitstream_release(bitstream_state_t *s) SPAN_DECLARE(int) bitstream_free(bitstream_state_t *s) { if (s) - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/complex_filters.c b/libs/spandsp/src/complex_filters.c index d54e55818a..22cf4ac9b8 100644 --- a/libs/spandsp/src/complex_filters.c +++ b/libs/spandsp/src/complex_filters.c @@ -32,6 +32,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/complex.h" #include "spandsp/complex_filters.h" @@ -40,7 +41,7 @@ SPAN_DECLARE(filter_t *) filter_create(fspec_t *fs) int i; filter_t *fi; - if ((fi = (filter_t *) malloc(sizeof(*fi) + sizeof(float)*(fs->np + 1)))) + if ((fi = (filter_t *) span_alloc(sizeof(*fi) + sizeof(float)*(fs->np + 1)))) { fi->fs = fs; fi->sum = 0.0; @@ -56,7 +57,7 @@ SPAN_DECLARE(filter_t *) filter_create(fspec_t *fs) SPAN_DECLARE(void) filter_delete(filter_t *fi) { if (fi) - free(fi); + span_free(fi); } /*- End of function --------------------------------------------------------*/ @@ -70,17 +71,17 @@ SPAN_DECLARE(cfilter_t *) cfilter_create(fspec_t *fs) { cfilter_t *cfi; - if ((cfi = (cfilter_t *) malloc(sizeof(*cfi)))) + if ((cfi = (cfilter_t *) span_alloc(sizeof(*cfi)))) { if ((cfi->ref = filter_create(fs)) == NULL) { - free(cfi); + span_free(cfi); return NULL; } if ((cfi->imf = filter_create(fs)) == NULL) { - free(cfi->ref); - free(cfi); + span_free(cfi->ref); + span_free(cfi); return NULL; } } diff --git a/libs/spandsp/src/dtmf.c b/libs/spandsp/src/dtmf.c index 991f3d6a85..e58552de58 100644 --- a/libs/spandsp/src/dtmf.c +++ b/libs/spandsp/src/dtmf.c @@ -43,6 +43,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/fast_convert.h" #include "spandsp/queue.h" @@ -413,7 +414,7 @@ SPAN_DECLARE(dtmf_rx_state_t *) dtmf_rx_init(dtmf_rx_state_t *s, if (s == NULL) { - if ((s = (dtmf_rx_state_t *) malloc(sizeof (*s))) == NULL) + if ((s = (dtmf_rx_state_t *) span_alloc(sizeof (*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -466,7 +467,7 @@ SPAN_DECLARE(int) dtmf_rx_release(dtmf_rx_state_t *s) SPAN_DECLARE(int) dtmf_rx_free(dtmf_rx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ @@ -578,7 +579,7 @@ SPAN_DECLARE(dtmf_tx_state_t *) dtmf_tx_init(dtmf_tx_state_t *s, { if (s == NULL) { - if ((s = (dtmf_tx_state_t *) malloc(sizeof (*s))) == NULL) + if ((s = (dtmf_tx_state_t *) span_alloc(sizeof (*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -603,7 +604,7 @@ SPAN_DECLARE(int) dtmf_tx_release(dtmf_tx_state_t *s) SPAN_DECLARE(int) dtmf_tx_free(dtmf_tx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/echo.c b/libs/spandsp/src/echo.c index 84926fa3c4..18c4ba4c1f 100644 --- a/libs/spandsp/src/echo.c +++ b/libs/spandsp/src/echo.c @@ -93,6 +93,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/logging.h" #include "spandsp/saturated.h" @@ -244,26 +245,26 @@ SPAN_DECLARE(echo_can_state_t *) echo_can_init(int len, int adaption_mode) int i; int j; - if ((ec = (echo_can_state_t *) malloc(sizeof(*ec))) == NULL) + if ((ec = (echo_can_state_t *) span_alloc(sizeof(*ec))) == NULL) return NULL; memset(ec, 0, sizeof(*ec)); ec->taps = len; ec->curr_pos = ec->taps - 1; ec->tap_mask = ec->taps - 1; - if ((ec->fir_taps32 = (int32_t *) malloc(ec->taps*sizeof(int32_t))) == NULL) + if ((ec->fir_taps32 = (int32_t *) span_alloc(ec->taps*sizeof(int32_t))) == NULL) { - free(ec); + span_free(ec); return NULL; } memset(ec->fir_taps32, 0, ec->taps*sizeof(int32_t)); for (i = 0; i < 4; i++) { - if ((ec->fir_taps16[i] = (int16_t *) malloc(ec->taps*sizeof(int16_t))) == NULL) + if ((ec->fir_taps16[i] = (int16_t *) span_alloc(ec->taps*sizeof(int16_t))) == NULL) { for (j = 0; j < i; j++) - free(ec->fir_taps16[j]); - free(ec->fir_taps32); - free(ec); + span_free(ec->fir_taps16[j]); + span_free(ec->fir_taps32); + span_free(ec); return NULL; } memset(ec->fir_taps16[i], 0, ec->taps*sizeof(int16_t)); @@ -294,10 +295,10 @@ SPAN_DECLARE(int) echo_can_free(echo_can_state_t *ec) int i; fir16_free(&ec->fir_state); - free(ec->fir_taps32); + span_free(ec->fir_taps32); for (i = 0; i < 4; i++) - free(ec->fir_taps16[i]); - free(ec); + span_free(ec->fir_taps16[i]); + span_free(ec); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/fax.c b/libs/spandsp/src/fax.c index ef7e33433a..b07aa002c5 100644 --- a/libs/spandsp/src/fax.c +++ b/libs/spandsp/src/fax.c @@ -50,6 +50,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/queue.h" #include "spandsp/dc_restore.h" @@ -470,7 +471,7 @@ SPAN_DECLARE(fax_state_t *) fax_init(fax_state_t *s, int calling_party) if (s == NULL) { - if ((s = (fax_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (fax_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -525,7 +526,7 @@ SPAN_DECLARE(int) fax_release(fax_state_t *s) SPAN_DECLARE(int) fax_free(fax_state_t *s) { t30_release(&s->t30); - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/fax_modems.c b/libs/spandsp/src/fax_modems.c index 3cf658e4df..69698bcaeb 100644 --- a/libs/spandsp/src/fax_modems.c +++ b/libs/spandsp/src/fax_modems.c @@ -48,6 +48,7 @@ #endif #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/bit_operations.h" #include "spandsp/dc_restore.h" @@ -503,7 +504,7 @@ SPAN_DECLARE(fax_modems_state_t *) fax_modems_init(fax_modems_state_t *s, { if (s == NULL) { - if ((s = (fax_modems_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (fax_modems_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } /*endif*/ @@ -562,7 +563,7 @@ SPAN_DECLARE(int) fax_modems_release(fax_modems_state_t *s) SPAN_DECLARE(int) fax_modems_free(fax_modems_state_t *s) { if (s) - free(s); + span_free(s); /*endif*/ return 0; } diff --git a/libs/spandsp/src/g711.c b/libs/spandsp/src/g711.c index 173bd2ae53..edccd27bb1 100644 --- a/libs/spandsp/src/g711.c +++ b/libs/spandsp/src/g711.c @@ -35,6 +35,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/bit_operations.h" #include "spandsp/g711.h" #include "spandsp/private/g711.h" @@ -171,7 +172,7 @@ SPAN_DECLARE(g711_state_t *) g711_init(g711_state_t *s, int mode) { if (s == NULL) { - if ((s = (g711_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (g711_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } s->mode = mode; @@ -187,7 +188,7 @@ SPAN_DECLARE(int) g711_release(g711_state_t *s) SPAN_DECLARE(int) g711_free(g711_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/g722.c b/libs/spandsp/src/g722.c index 22715cfa4a..bbf3bbfc0f 100644 --- a/libs/spandsp/src/g722.c +++ b/libs/spandsp/src/g722.c @@ -41,6 +41,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/saturated.h" #include "spandsp/vector_int.h" @@ -251,7 +252,7 @@ SPAN_DECLARE(g722_decode_state_t *) g722_decode_init(g722_decode_state_t *s, int { if (s == NULL) { - if ((s = (g722_decode_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (g722_decode_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -281,7 +282,7 @@ SPAN_DECLARE(int) g722_decode_release(g722_decode_state_t *s) SPAN_DECLARE(int) g722_decode_free(g722_decode_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ @@ -432,7 +433,7 @@ SPAN_DECLARE(g722_encode_state_t *) g722_encode_init(g722_encode_state_t *s, int { if (s == NULL) { - if ((s = (g722_encode_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (g722_encode_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -462,7 +463,7 @@ SPAN_DECLARE(int) g722_encode_release(g722_encode_state_t *s) SPAN_DECLARE(int) g722_encode_free(g722_encode_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/g726.c b/libs/spandsp/src/g726.c index 6be385fc5f..ba1c5b913e 100644 --- a/libs/spandsp/src/g726.c +++ b/libs/spandsp/src/g726.c @@ -67,6 +67,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/bitstream.h" #include "spandsp/bit_operations.h" #include "spandsp/g711.h" @@ -1002,7 +1003,7 @@ SPAN_DECLARE(g726_state_t *) g726_init(g726_state_t *s, int bit_rate, int ext_co return NULL; if (s == NULL) { - if ((s = (g726_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (g726_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } s->yl = 34816; @@ -1062,7 +1063,7 @@ SPAN_DECLARE(int) g726_release(g726_state_t *s) SPAN_DECLARE(int) g726_free(g726_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/gsm0610_encode.c b/libs/spandsp/src/gsm0610_encode.c index 2c359688fe..eeac7d2881 100644 --- a/libs/spandsp/src/gsm0610_encode.c +++ b/libs/spandsp/src/gsm0610_encode.c @@ -45,6 +45,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/bitstream.h" #include "spandsp/saturated.h" @@ -115,7 +116,7 @@ SPAN_DECLARE(gsm0610_state_t *) gsm0610_init(gsm0610_state_t *s, int packing) { if (s == NULL) { - if ((s = (gsm0610_state_t *) malloc(sizeof (*s))) == NULL) + if ((s = (gsm0610_state_t *) span_alloc(sizeof (*s))) == NULL) return NULL; /*endif*/ } @@ -136,7 +137,7 @@ SPAN_DECLARE(int) gsm0610_release(gsm0610_state_t *s) SPAN_DECLARE(int) gsm0610_free(gsm0610_state_t *s) { if (s) - free(s); + span_free(s); /*endif*/ return 0; } diff --git a/libs/spandsp/src/logging.c b/libs/spandsp/src/logging.c index 3f9aa58f17..68975b0e04 100644 --- a/libs/spandsp/src/logging.c +++ b/libs/spandsp/src/logging.c @@ -42,6 +42,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/private/logging.h" @@ -229,7 +230,7 @@ SPAN_DECLARE(logging_state_t *) span_log_init(logging_state_t *s, int level, con { if (s == NULL) { - if ((s = (logging_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (logging_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } s->span_message = __span_message; @@ -252,7 +253,7 @@ SPAN_DECLARE(int) span_log_release(logging_state_t *s) SPAN_DECLARE(int) span_log_free(logging_state_t *s) { if (s) - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/lpc10_decode.c b/libs/spandsp/src/lpc10_decode.c index 19860e149d..eb6d9968cb 100644 --- a/libs/spandsp/src/lpc10_decode.c +++ b/libs/spandsp/src/lpc10_decode.c @@ -44,6 +44,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/lpc10.h" #include "spandsp/private/lpc10.h" @@ -1016,7 +1017,7 @@ SPAN_DECLARE(lpc10_decode_state_t *) lpc10_decode_init(lpc10_decode_state_t *s, if (s == NULL) { - if ((s = (lpc10_decode_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (lpc10_decode_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } @@ -1084,7 +1085,7 @@ SPAN_DECLARE(int) lpc10_decode_release(lpc10_decode_state_t *s) SPAN_DECLARE(int) lpc10_decode_free(lpc10_decode_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/lpc10_encode.c b/libs/spandsp/src/lpc10_encode.c index 739734f866..976fc602d0 100644 --- a/libs/spandsp/src/lpc10_encode.c +++ b/libs/spandsp/src/lpc10_encode.c @@ -44,6 +44,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/lpc10.h" #include "spandsp/private/lpc10.h" @@ -269,7 +270,7 @@ SPAN_DECLARE(lpc10_encode_state_t *) lpc10_encode_init(lpc10_encode_state_t *s, if (s == NULL) { - if ((s = (lpc10_encode_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (lpc10_encode_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } @@ -367,7 +368,7 @@ SPAN_DECLARE(int) lpc10_encode_release(lpc10_encode_state_t *s) SPAN_DECLARE(int) lpc10_encode_free(lpc10_encode_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/modem_connect_tones.c b/libs/spandsp/src/modem_connect_tones.c index 76b42a23fc..6a08781f66 100644 --- a/libs/spandsp/src/modem_connect_tones.c +++ b/libs/spandsp/src/modem_connect_tones.c @@ -57,6 +57,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/logging.h" #include "spandsp/complex.h" @@ -258,7 +259,7 @@ SPAN_DECLARE(modem_connect_tones_tx_state_t *) modem_connect_tones_tx_init(modem alloced = FALSE; if (s == NULL) { - if ((s = (modem_connect_tones_tx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (modem_connect_tones_tx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; alloced = TRUE; } @@ -341,7 +342,7 @@ SPAN_DECLARE(modem_connect_tones_tx_state_t *) modem_connect_tones_tx_init(modem break; default: if (alloced) - free(s); + span_free(s); return NULL; } return s; @@ -356,7 +357,7 @@ SPAN_DECLARE(int) modem_connect_tones_tx_release(modem_connect_tones_tx_state_t SPAN_DECLARE(int) modem_connect_tones_tx_free(modem_connect_tones_tx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ @@ -716,7 +717,7 @@ SPAN_DECLARE(modem_connect_tones_rx_state_t *) modem_connect_tones_rx_init(modem { if (s == NULL) { - if ((s = (modem_connect_tones_rx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (modem_connect_tones_rx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } @@ -765,7 +766,7 @@ SPAN_DECLARE(int) modem_connect_tones_rx_release(modem_connect_tones_rx_state_t SPAN_DECLARE(int) modem_connect_tones_rx_free(modem_connect_tones_rx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/modem_echo.c b/libs/spandsp/src/modem_echo.c index 14257c7eb7..59bf57b544 100644 --- a/libs/spandsp/src/modem_echo.c +++ b/libs/spandsp/src/modem_echo.c @@ -47,6 +47,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/bit_operations.h" #include "spandsp/dc_restore.h" #include "spandsp/modem_echo.h" @@ -66,29 +67,29 @@ SPAN_DECLARE(modem_echo_can_state_t *) modem_echo_can_init(int len) { modem_echo_can_state_t *ec; - if ((ec = (modem_echo_can_state_t *) malloc(sizeof(*ec))) == NULL) + if ((ec = (modem_echo_can_state_t *) span_alloc(sizeof(*ec))) == NULL) return NULL; memset(ec, 0, sizeof(*ec)); ec->taps = len; ec->curr_pos = ec->taps - 1; - if ((ec->fir_taps32 = (int32_t *) malloc(ec->taps*sizeof(int32_t))) == NULL) + if ((ec->fir_taps32 = (int32_t *) span_alloc(ec->taps*sizeof(int32_t))) == NULL) { free(ec); return NULL; } memset(ec->fir_taps32, 0, ec->taps*sizeof(int32_t)); - if ((ec->fir_taps16 = (int16_t *) malloc(ec->taps*sizeof(int16_t))) == NULL) + if ((ec->fir_taps16 = (int16_t *) span_alloc(ec->taps*sizeof(int16_t))) == NULL) { - free(ec->fir_taps32); - free(ec); + span_free(ec->fir_taps32); + span_free(ec); return NULL; } memset(ec->fir_taps16, 0, ec->taps*sizeof(int16_t)); if (fir16_create(&ec->fir_state, ec->fir_taps16, ec->taps) == NULL) { - free(ec->fir_taps16); - free(ec->fir_taps32); - free(ec); + span_free(ec->fir_taps16); + span_free(ec->fir_taps32); + span_free(ec); return NULL; } return ec; diff --git a/libs/spandsp/src/noise.c b/libs/spandsp/src/noise.c index 5d7fe23aad..3ad164cf7f 100644 --- a/libs/spandsp/src/noise.c +++ b/libs/spandsp/src/noise.c @@ -43,6 +43,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/saturated.h" #include "spandsp/noise.h" @@ -84,7 +85,7 @@ SPAN_DECLARE(noise_state_t *) noise_init_dbov(noise_state_t *s, int seed, float if (s == NULL) { - if ((s = (noise_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (noise_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -121,7 +122,7 @@ SPAN_DECLARE(int) noise_release(noise_state_t *s) SPAN_DECLARE(int) noise_free(noise_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/oki_adpcm.c b/libs/spandsp/src/oki_adpcm.c index f6d54b804c..0e5e8f6659 100644 --- a/libs/spandsp/src/oki_adpcm.c +++ b/libs/spandsp/src/oki_adpcm.c @@ -39,6 +39,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/oki_adpcm.h" #include "spandsp/private/oki_adpcm.h" @@ -246,7 +247,7 @@ SPAN_DECLARE(oki_adpcm_state_t *) oki_adpcm_init(oki_adpcm_state_t *s, int bit_r return NULL; if (s == NULL) { - if ((s = (oki_adpcm_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (oki_adpcm_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -264,7 +265,7 @@ SPAN_DECLARE(int) oki_adpcm_release(oki_adpcm_state_t *s) SPAN_DECLARE(int) oki_adpcm_free(oki_adpcm_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/playout.c b/libs/spandsp/src/playout.c index e98e48d70c..60a8d97674 100644 --- a/libs/spandsp/src/playout.c +++ b/libs/spandsp/src/playout.c @@ -41,6 +41,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/playout.h" static playout_frame_t *queue_get(playout_state_t *s, timestamp_t sender_stamp) @@ -236,7 +237,7 @@ SPAN_DECLARE(int) playout_put(playout_state_t *s, void *data, int type, timestam } else { - if ((frame = (playout_frame_t *) malloc(sizeof(*frame))) == NULL) + if ((frame = (playout_frame_t *) span_alloc(sizeof(*frame))) == NULL) return PLAYOUT_ERROR; } @@ -312,7 +313,7 @@ SPAN_DECLARE(void) playout_restart(playout_state_t *s, int min_length, int max_l for (frame = s->free_frames; frame; frame = next) { next = frame->later; - free(frame); + span_free(frame); } memset(s, 0, sizeof(*s)); @@ -332,7 +333,7 @@ SPAN_DECLARE(playout_state_t *) playout_init(int min_length, int max_length) { playout_state_t *s; - if ((s = (playout_state_t *) malloc(sizeof(playout_state_t))) == NULL) + if ((s = (playout_state_t *) span_alloc(sizeof(playout_state_t))) == NULL) return NULL; memset(s, 0, sizeof(*s)); playout_restart(s, min_length, max_length); @@ -350,13 +351,13 @@ SPAN_DECLARE(int) playout_release(playout_state_t *s) for (frame = s->first_frame; frame; frame = next) { next = frame->later; - free(frame); + span_free(frame); } /* Free all the frames on the free list */ for (frame = s->free_frames; frame; frame = next) { next = frame->later; - free(frame); + span_free(frame); } return 0; } @@ -368,7 +369,7 @@ SPAN_DECLARE(int) playout_free(playout_state_t *s) { playout_release(s); /* Finally, free ourselves! */ - free(s); + span_free(s); } return 0; } diff --git a/libs/spandsp/src/plc.c b/libs/spandsp/src/plc.c index dcb07120e1..840682a8fc 100644 --- a/libs/spandsp/src/plc.c +++ b/libs/spandsp/src/plc.c @@ -43,6 +43,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/saturated.h" #include "spandsp/plc.h" @@ -234,7 +235,7 @@ SPAN_DECLARE(plc_state_t *) plc_init(plc_state_t *s) { if (s == NULL) { - if ((s = (plc_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (plc_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -251,7 +252,7 @@ SPAN_DECLARE(int) plc_release(plc_state_t *s) SPAN_DECLARE(int) plc_free(plc_state_t *s) { if (s) - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/power_meter.c b/libs/spandsp/src/power_meter.c index f4fb2afa8f..9843930215 100644 --- a/libs/spandsp/src/power_meter.c +++ b/libs/spandsp/src/power_meter.c @@ -45,13 +45,14 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/power_meter.h" SPAN_DECLARE(power_meter_t *) power_meter_init(power_meter_t *s, int shift) { if (s == NULL) { - if ((s = (power_meter_t *) malloc(sizeof(*s))) == NULL) + if ((s = (power_meter_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } s->shift = shift; @@ -69,7 +70,7 @@ SPAN_DECLARE(int) power_meter_release(power_meter_t *s) SPAN_DECLARE(int) power_meter_free(power_meter_t *s) { if (s) - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ @@ -181,7 +182,7 @@ SPAN_DECLARE(power_surge_detector_state_t *) power_surge_detector_init(power_sur if (s == NULL) { - if ((s = (power_surge_detector_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (power_surge_detector_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -205,7 +206,7 @@ SPAN_DECLARE(int) power_surge_detector_release(power_surge_detector_state_t *s) SPAN_DECLARE(int) power_surge_detector_free(power_surge_detector_state_t *s) { if (s) - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/queue.c b/libs/spandsp/src/queue.c index 264cee0c87..3f55e833ea 100644 --- a/libs/spandsp/src/queue.c +++ b/libs/spandsp/src/queue.c @@ -39,6 +39,7 @@ #define SPANDSP_FULLY_DEFINE_QUEUE_STATE_T #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/queue.h" #include "spandsp/private/queue.h" @@ -395,7 +396,7 @@ SPAN_DECLARE(queue_state_t *) queue_init(queue_state_t *s, int len, int flags) { if (s == NULL) { - if ((s = (queue_state_t *) malloc(sizeof(*s) + len + 1)) == NULL) + if ((s = (queue_state_t *) span_alloc(sizeof(*s) + len + 1)) == NULL) return NULL; } s->iptr = @@ -414,7 +415,7 @@ SPAN_DECLARE(int) queue_release(queue_state_t *s) SPAN_DECLARE(int) queue_free(queue_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/schedule.c b/libs/spandsp/src/schedule.c index 60ba12bc1f..f65b5d7764 100644 --- a/libs/spandsp/src/schedule.c +++ b/libs/spandsp/src/schedule.c @@ -33,6 +33,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/schedule.h" @@ -53,7 +54,7 @@ SPAN_DECLARE(int) span_schedule_event(span_sched_state_t *s, int us, span_sched_ if (i >= s->allocated) { s->allocated += 5; - s->sched = (span_sched_t *) realloc(s->sched, sizeof(span_sched_t)*s->allocated); + s->sched = (span_sched_t *) span_realloc(s->sched, sizeof(span_sched_t)*s->allocated); } /*endif*/ if (i >= s->max_to_date) @@ -141,7 +142,7 @@ SPAN_DECLARE(int) span_schedule_release(span_sched_state_t *s) { if (s->sched) { - free(s->sched); + span_free(s->sched); s->sched = NULL; } return 0; @@ -152,7 +153,7 @@ SPAN_DECLARE(int) span_schedule_free(span_sched_state_t *s) { span_schedule_release(s); if (s) - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/sig_tone.c b/libs/spandsp/src/sig_tone.c index 5e4e180178..698c07180e 100644 --- a/libs/spandsp/src/sig_tone.c +++ b/libs/spandsp/src/sig_tone.c @@ -44,6 +44,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/saturated.h" #include "spandsp/vector_int.h" @@ -325,7 +326,7 @@ SPAN_DECLARE(sig_tone_tx_state_t *) sig_tone_tx_init(sig_tone_tx_state_t *s, int if (s == NULL) { - if ((s = (sig_tone_tx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (sig_tone_tx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -357,7 +358,7 @@ SPAN_DECLARE(int) sig_tone_tx_release(sig_tone_tx_state_t *s) SPAN_DECLARE(int) sig_tone_tx_free(sig_tone_tx_state_t *s) { if (s) - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ @@ -641,7 +642,7 @@ SPAN_DECLARE(sig_tone_rx_state_t *) sig_tone_rx_init(sig_tone_rx_state_t *s, int if (s == NULL) { - if ((s = (sig_tone_rx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (sig_tone_rx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -685,7 +686,7 @@ SPAN_DECLARE(int) sig_tone_rx_release(sig_tone_rx_state_t *s) SPAN_DECLARE(int) sig_tone_rx_free(sig_tone_rx_state_t *s) { if (s) - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/silence_gen.c b/libs/spandsp/src/silence_gen.c index ad7d7caed0..d89f9c8e42 100644 --- a/libs/spandsp/src/silence_gen.c +++ b/libs/spandsp/src/silence_gen.c @@ -45,6 +45,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/async.h" #include "spandsp/silence_gen.h" @@ -119,7 +120,7 @@ SPAN_DECLARE(silence_gen_state_t *) silence_gen_init(silence_gen_state_t *s, int { if (s == NULL) { - if ((s = (silence_gen_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (silence_gen_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -137,7 +138,7 @@ SPAN_DECLARE(int) silence_gen_release(silence_gen_state_t *s) SPAN_DECLARE(int) silence_gen_free(silence_gen_state_t *s) { if (s) - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/super_tone_rx.c b/libs/spandsp/src/super_tone_rx.c index e46faa8148..eabebe6a30 100644 --- a/libs/spandsp/src/super_tone_rx.c +++ b/libs/spandsp/src/super_tone_rx.c @@ -45,6 +45,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/complex.h" #include "spandsp/vector_float.h" @@ -95,7 +96,7 @@ static int add_super_tone_freq(super_tone_rx_descriptor_t *desc, int freq) desc->pitches[i][1] = desc->monitored_frequencies; if (desc->monitored_frequencies%5 == 0) { - desc->desc = (goertzel_descriptor_t *) realloc(desc->desc, (desc->monitored_frequencies + 5)*sizeof(goertzel_descriptor_t)); + desc->desc = (goertzel_descriptor_t *) span_realloc(desc->desc, (desc->monitored_frequencies + 5)*sizeof(goertzel_descriptor_t)); } make_goertzel_descriptor(&desc->desc[desc->monitored_frequencies++], (float) freq, SUPER_TONE_BINS); desc->used_frequencies++; @@ -107,8 +108,8 @@ SPAN_DECLARE(int) super_tone_rx_add_tone(super_tone_rx_descriptor_t *desc) { if (desc->tones%5 == 0) { - desc->tone_list = (super_tone_rx_segment_t **) realloc(desc->tone_list, (desc->tones + 5)*sizeof(super_tone_rx_segment_t *)); - desc->tone_segs = (int *) realloc(desc->tone_segs, (desc->tones + 5)*sizeof(int)); + desc->tone_list = (super_tone_rx_segment_t **) span_realloc(desc->tone_list, (desc->tones + 5)*sizeof(super_tone_rx_segment_t *)); + desc->tone_segs = (int *) span_realloc(desc->tone_segs, (desc->tones + 5)*sizeof(int)); } desc->tone_list[desc->tones] = NULL; desc->tone_segs[desc->tones] = 0; @@ -129,7 +130,7 @@ SPAN_DECLARE(int) super_tone_rx_add_element(super_tone_rx_descriptor_t *desc, step = desc->tone_segs[tone]; if (step%5 == 0) { - desc->tone_list[tone] = (super_tone_rx_segment_t *) realloc(desc->tone_list[tone], (step + 5)*sizeof(super_tone_rx_segment_t)); + desc->tone_list[tone] = (super_tone_rx_segment_t *) span_realloc(desc->tone_list[tone], (step + 5)*sizeof(super_tone_rx_segment_t)); } desc->tone_list[tone][step].f1 = add_super_tone_freq(desc, f1); desc->tone_list[tone][step].f2 = add_super_tone_freq(desc, f2); @@ -199,7 +200,7 @@ SPAN_DECLARE(super_tone_rx_descriptor_t *) super_tone_rx_make_descriptor(super_t { if (desc == NULL) { - if ((desc = (super_tone_rx_descriptor_t *) malloc(sizeof(*desc))) == NULL) + if ((desc = (super_tone_rx_descriptor_t *) span_alloc(sizeof(*desc))) == NULL) return NULL; } desc->tone_list = NULL; @@ -222,15 +223,15 @@ SPAN_DECLARE(int) super_tone_rx_free_descriptor(super_tone_rx_descriptor_t *desc for (i = 0; i < desc->tones; i++) { if (desc->tone_list[i]) - free(desc->tone_list[i]); + span_free(desc->tone_list[i]); } if (desc->tone_list) - free(desc->tone_list); + span_free(desc->tone_list); if (desc->tone_segs) - free(desc->tone_segs); + span_free(desc->tone_segs); if (desc->desc) - free(desc->desc); - free(desc); + span_free(desc->desc); + span_free(desc); } return 0; } @@ -265,7 +266,7 @@ SPAN_DECLARE(super_tone_rx_state_t *) super_tone_rx_init(super_tone_rx_state_t * return NULL; if (s == NULL) { - if ((s = (super_tone_rx_state_t *) malloc(sizeof(*s) + desc->monitored_frequencies*sizeof(goertzel_state_t))) == NULL) + if ((s = (super_tone_rx_state_t *) span_alloc(sizeof(*s) + desc->monitored_frequencies*sizeof(goertzel_state_t))) == NULL) return NULL; } @@ -301,7 +302,7 @@ SPAN_DECLARE(int) super_tone_rx_release(super_tone_rx_state_t *s) SPAN_DECLARE(int) super_tone_rx_free(super_tone_rx_state_t *s) { if (s) - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/super_tone_tx.c b/libs/spandsp/src/super_tone_tx.c index 3809bb4bf8..5b8ab4303d 100644 --- a/libs/spandsp/src/super_tone_tx.c +++ b/libs/spandsp/src/super_tone_tx.c @@ -45,6 +45,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/complex.h" #include "spandsp/dds.h" @@ -78,7 +79,7 @@ SPAN_DECLARE(super_tone_tx_step_t *) super_tone_tx_make_step(super_tone_tx_step_ { if (s == NULL) { - if ((s = (super_tone_tx_step_t *) malloc(sizeof(*s))) == NULL) + if ((s = (super_tone_tx_step_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } if (f1 >= 1.0f) @@ -121,7 +122,7 @@ SPAN_DECLARE(int) super_tone_tx_free_tone(super_tone_tx_step_t *s) super_tone_tx_free_tone(s->nest); t = s; s = s->next; - free(t); + span_free(t); } return 0; } @@ -133,7 +134,7 @@ SPAN_DECLARE(super_tone_tx_state_t *) super_tone_tx_init(super_tone_tx_state_t * return NULL; if (s == NULL) { - if ((s = (super_tone_tx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (super_tone_tx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -155,7 +156,7 @@ SPAN_DECLARE(int) super_tone_tx_release(super_tone_tx_state_t *s) SPAN_DECLARE(int) super_tone_tx_free(super_tone_tx_state_t *s) { if (s) - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/swept_tone.c b/libs/spandsp/src/swept_tone.c index f5ccc9bed8..20eb7d5de9 100644 --- a/libs/spandsp/src/swept_tone.c +++ b/libs/spandsp/src/swept_tone.c @@ -42,6 +42,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/complex.h" #include "spandsp/vector_float.h" @@ -59,7 +60,7 @@ SPAN_DECLARE(swept_tone_state_t *) swept_tone_init(swept_tone_state_t *s, float { if (s == NULL) { - if ((s = (swept_tone_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (swept_tone_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -119,7 +120,7 @@ SPAN_DECLARE(int) swept_tone_release(swept_tone_state_t *s) SPAN_DECLARE(int) swept_tone_free(swept_tone_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/t30_api.c b/libs/spandsp/src/t30_api.c index 7ab68677c3..d00ede33d2 100644 --- a/libs/spandsp/src/t30_api.c +++ b/libs/spandsp/src/t30_api.c @@ -45,6 +45,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/bit_operations.h" #include "spandsp/queue.h" @@ -277,8 +278,8 @@ SPAN_DECLARE(const char *) t30_get_rx_password(t30_state_t *s) SPAN_DECLARE(int) t30_set_tx_nsf(t30_state_t *s, const uint8_t *nsf, int len) { if (s->tx_info.nsf) - free(s->tx_info.nsf); - if (nsf && len > 0 && (s->tx_info.nsf = malloc(len + 3))) + span_free(s->tx_info.nsf); + if (nsf && len > 0 && (s->tx_info.nsf = span_alloc(len + 3))) { memcpy(s->tx_info.nsf + 3, nsf, len); s->tx_info.nsf_len = len; @@ -311,8 +312,8 @@ SPAN_DECLARE(size_t) t30_get_rx_nsf(t30_state_t *s, const uint8_t *nsf[]) SPAN_DECLARE(int) t30_set_tx_nsc(t30_state_t *s, const uint8_t *nsc, int len) { if (s->tx_info.nsc) - free(s->tx_info.nsc); - if (nsc && len > 0 && (s->tx_info.nsc = malloc(len + 3))) + span_free(s->tx_info.nsc); + if (nsc && len > 0 && (s->tx_info.nsc = span_alloc(len + 3))) { memcpy(s->tx_info.nsc + 3, nsc, len); s->tx_info.nsc_len = len; @@ -345,8 +346,8 @@ SPAN_DECLARE(size_t) t30_get_rx_nsc(t30_state_t *s, const uint8_t *nsc[]) SPAN_DECLARE(int) t30_set_tx_nss(t30_state_t *s, const uint8_t *nss, int len) { if (s->tx_info.nss) - free(s->tx_info.nss); - if (nss && len > 0 && (s->tx_info.nss = malloc(len + 3))) + span_free(s->tx_info.nss); + if (nss && len > 0 && (s->tx_info.nss = span_alloc(len + 3))) { memcpy(s->tx_info.nss + 3, nss, len); s->tx_info.nss_len = len; @@ -379,7 +380,7 @@ SPAN_DECLARE(size_t) t30_get_rx_nss(t30_state_t *s, const uint8_t *nss[]) SPAN_DECLARE(int) t30_set_tx_tsa(t30_state_t *s, int type, const char *address, int len) { if (s->tx_info.tsa) - free(s->tx_info.tsa); + span_free(s->tx_info.tsa); if (address == NULL || len == 0) { s->tx_info.tsa = NULL; @@ -389,7 +390,7 @@ SPAN_DECLARE(int) t30_set_tx_tsa(t30_state_t *s, int type, const char *address, s->tx_info.tsa_type = type; if (len < 0) len = strlen(address); - if ((s->tx_info.tsa = malloc(len))) + if ((s->tx_info.tsa = span_alloc(len))) { memcpy(s->tx_info.tsa, address, len); s->tx_info.tsa_len = len; @@ -421,7 +422,7 @@ SPAN_DECLARE(size_t) t30_get_rx_tsa(t30_state_t *s, int *type, const char *addre SPAN_DECLARE(int) t30_set_tx_ira(t30_state_t *s, int type, const char *address, int len) { if (s->tx_info.ira) - free(s->tx_info.ira); + span_free(s->tx_info.ira); if (address == NULL) { s->tx_info.ira = NULL; @@ -455,7 +456,7 @@ SPAN_DECLARE(size_t) t30_get_rx_ira(t30_state_t *s, int *type, const char *addre SPAN_DECLARE(int) t30_set_tx_cia(t30_state_t *s, int type, const char *address, int len) { if (s->tx_info.cia) - free(s->tx_info.cia); + span_free(s->tx_info.cia); if (address == NULL) { s->tx_info.cia = NULL; @@ -489,7 +490,7 @@ SPAN_DECLARE(size_t) t30_get_rx_cia(t30_state_t *s, int *type, const char *addre SPAN_DECLARE(int) t30_set_tx_isp(t30_state_t *s, int type, const char *address, int len) { if (s->tx_info.isp) - free(s->tx_info.isp); + span_free(s->tx_info.isp); if (address == NULL) { s->tx_info.isp = NULL; @@ -523,7 +524,7 @@ SPAN_DECLARE(size_t) t30_get_rx_isp(t30_state_t *s, int *type, const char *addre SPAN_DECLARE(int) t30_set_tx_csa(t30_state_t *s, int type, const char *address, int len) { if (s->tx_info.csa) - free(s->tx_info.csa); + span_free(s->tx_info.csa); if (address == NULL) { s->tx_info.csa = NULL; diff --git a/libs/spandsp/src/t81_t82_arith_coding.c b/libs/spandsp/src/t81_t82_arith_coding.c index 86e7e0271f..5d51bbc25d 100644 --- a/libs/spandsp/src/t81_t82_arith_coding.c +++ b/libs/spandsp/src/t81_t82_arith_coding.c @@ -35,6 +35,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/t81_t82_arith_coding.h" #include "spandsp/private/t81_t82_arith_coding.h" @@ -341,7 +342,7 @@ SPAN_DECLARE(t81_t82_arith_encode_state_t *) t81_t82_arith_encode_init(t81_t82_a { if (s == NULL) { - if ((s = (t81_t82_arith_encode_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t81_t82_arith_encode_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -364,7 +365,7 @@ SPAN_DECLARE(int) t81_t82_arith_encode_free(t81_t82_arith_encode_state_t *s) int ret; ret = t81_t82_arith_encode_release(s); - free(s); + span_free(s); return ret; } /*- End of function --------------------------------------------------------*/ @@ -481,7 +482,7 @@ SPAN_DECLARE(t81_t82_arith_decode_state_t *) t81_t82_arith_decode_init(t81_t82_a { if (s == NULL) { - if ((s = (t81_t82_arith_decode_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t81_t82_arith_decode_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -502,7 +503,7 @@ SPAN_DECLARE(int) t81_t82_arith_decode_free(t81_t82_arith_decode_state_t *s) int ret; ret = t81_t82_arith_decode_release(s); - free(s); + span_free(s); return ret; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/t85_decode.c b/libs/spandsp/src/t85_decode.c index 93efc06e81..f48502c9d9 100644 --- a/libs/spandsp/src/t85_decode.c +++ b/libs/spandsp/src/t85_decode.c @@ -35,6 +35,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/async.h" #include "spandsp/timezone.h" @@ -399,7 +400,7 @@ SPAN_DECLARE(int) t85_decode_put(t85_decode_state_t *s, const uint8_t data[], si if (min_len > s->row_buf_len) { /* We need to expand the 3 row buffer */ - if ((buf = (uint8_t *) realloc(s->row_buf, min_len)) == NULL) + if ((buf = (uint8_t *) span_realloc(s->row_buf, min_len)) == NULL) return T4_DECODE_NOMEM; s->row_buf = buf; s->row_buf_len = min_len; @@ -409,7 +410,7 @@ SPAN_DECLARE(int) t85_decode_put(t85_decode_state_t *s, const uint8_t data[], si s->s.nopadding = s->options & T85_VLENGTH; if (s->comment) { - free(s->comment); + span_free(s->comment); s->comment = NULL; } s->comment_len = 0; @@ -455,7 +456,7 @@ SPAN_DECLARE(int) t85_decode_put(t85_decode_state_t *s, const uint8_t data[], si s->interrupt = s->comment_handler(s->comment_user_data, s->comment, s->comment_len); if (s->comment) { - free(s->comment); + span_free(s->comment); s->comment = NULL; } s->comment_len = 0; @@ -506,12 +507,12 @@ SPAN_DECLARE(int) t85_decode_put(t85_decode_state_t *s, const uint8_t data[], si s->comment_len = pack_32(&s->buffer[2]); /* Only try to buffer and process the comment's contents if we have a defined callback routine to do something with it. */ - /* If this malloc fails we carry on working just fine, and don't try to + /* If this allocate fails we carry on working just fine, and don't try to process the contents of the comment. That is fairly benign, as the comments are not generally of critical importance, so let's not worry. */ if (s->comment_handler && s->comment_len > 0 && s->comment_len <= s->max_comment_len) - s->comment = malloc(s->comment_len); + s->comment = span_alloc(s->comment_len); s->comment_progress = 0; continue; case T82_ATMOVE: @@ -738,7 +739,7 @@ SPAN_DECLARE(int) t85_decode_new_plane(t85_decode_state_t *s) s->end_of_data = 0; if (s->comment) { - free(s->comment); + span_free(s->comment); s->comment = NULL; } s->comment_len = 0; @@ -786,7 +787,7 @@ SPAN_DECLARE(int) t85_decode_restart(t85_decode_state_t *s) s->end_of_data = 0; if (s->comment) { - free(s->comment); + span_free(s->comment); s->comment = NULL; } s->comment_len = 0; @@ -811,7 +812,7 @@ SPAN_DECLARE(t85_decode_state_t *) t85_decode_init(t85_decode_state_t *s, { if (s == NULL) { - if ((s = (t85_decode_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t85_decode_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -837,12 +838,12 @@ SPAN_DECLARE(int) t85_decode_release(t85_decode_state_t *s) { if (s->row_buf) { - free(s->row_buf); + span_free(s->row_buf); s->row_buf = NULL; } if (s->comment) { - free(s->comment); + span_free(s->comment); s->comment = NULL; } return 0; @@ -854,7 +855,7 @@ SPAN_DECLARE(int) t85_decode_free(t85_decode_state_t *s) int ret; ret = t85_decode_release(s); - free(s); + span_free(s); return ret; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/t85_encode.c b/libs/spandsp/src/t85_encode.c index ed8e47364f..9b417a39fd 100644 --- a/libs/spandsp/src/t85_encode.c +++ b/libs/spandsp/src/t85_encode.c @@ -35,6 +35,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/async.h" #include "spandsp/timezone.h" @@ -78,7 +79,7 @@ static void put_stuff(t85_encode_state_t *s, const uint8_t buf[], int len) /* The number of uncompressed bytes per row seems like a reasonable measure of what to expect as a poor case for a compressed row. */ bytes_per_row = (s->xd + 7) >> 3; - if ((new_buf = realloc(s->bitstream, s->bitstream_len + len + bytes_per_row)) == NULL) + if ((new_buf = span_realloc(s->bitstream, s->bitstream_len + len + bytes_per_row)) == NULL) return; s->bitstream = new_buf; s->bitstream_len += (len + bytes_per_row); @@ -518,7 +519,7 @@ SPAN_DECLARE(int) t85_encode_set_image_width(t85_encode_state_t *s, uint32_t ima return -1; s->xd = image_width; bytes_per_row = (s->xd + 7) >> 3; - if ((t = (uint8_t *) realloc(s->row_buf, 3*bytes_per_row)) == NULL) + if ((t = (uint8_t *) span_realloc(s->row_buf, 3*bytes_per_row)) == NULL) return -1; s->row_buf = t; memset(s->row_buf, 0, 3*bytes_per_row); @@ -663,7 +664,7 @@ SPAN_DECLARE(int) t85_encode_restart(t85_encode_state_t *s, uint32_t image_width s->bitstream_optr = 0; if (s->bitstream) { - free(s->bitstream); + span_free(s->bitstream); s->bitstream = NULL; } s->bitstream_len = 0; @@ -689,7 +690,7 @@ SPAN_DECLARE(t85_encode_state_t *) t85_encode_init(t85_encode_state_t *s, { if (s == NULL) { - if ((s = (t85_encode_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t85_encode_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -722,12 +723,12 @@ SPAN_DECLARE(int) t85_encode_release(t85_encode_state_t *s) { if (s->row_buf) { - free(s->row_buf); + span_free(s->row_buf); s->row_buf = NULL; } if (s->bitstream) { - free(s->bitstream); + span_free(s->bitstream); s->bitstream = NULL; s->bitstream_len = 0; } @@ -740,7 +741,7 @@ SPAN_DECLARE(int) t85_encode_free(t85_encode_state_t *s) int ret; ret = t85_encode_release(s); - free(s); + span_free(s); return ret; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/time_scale.c b/libs/spandsp/src/time_scale.c index 5b2a64a66b..a817834d22 100644 --- a/libs/spandsp/src/time_scale.c +++ b/libs/spandsp/src/time_scale.c @@ -45,6 +45,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/time_scale.h" #include "spandsp/saturated.h" @@ -132,7 +133,7 @@ SPAN_DECLARE(time_scale_state_t *) time_scale_init(time_scale_state_t *s, int sa alloced = FALSE; if (s == NULL) { - if ((s = (time_scale_state_t *) malloc(sizeof (*s))) == NULL) + if ((s = (time_scale_state_t *) span_alloc(sizeof (*s))) == NULL) return NULL; /*endif*/ alloced = TRUE; @@ -145,7 +146,7 @@ SPAN_DECLARE(time_scale_state_t *) time_scale_init(time_scale_state_t *s, int sa if (time_scale_rate(s, playout_rate)) { if (alloced) - free(s); + span_free(s); return NULL; } /*endif*/ @@ -164,7 +165,7 @@ SPAN_DECLARE(int) time_scale_release(time_scale_state_t *s) SPAN_DECLARE(int) time_scale_free(time_scale_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/timezone.c b/libs/spandsp/src/timezone.c index 79966f1d4c..158b0100da 100644 --- a/libs/spandsp/src/timezone.c +++ b/libs/spandsp/src/timezone.c @@ -47,6 +47,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/timezone.h" #include "spandsp/private/timezone.h" @@ -796,7 +797,7 @@ SPAN_DECLARE(tz_t *) tz_init(tz_t *tz, const char *tzstring) { if (tz == NULL) { - if ((tz = (tz_t *) malloc(sizeof(*tz))) == NULL) + if ((tz = (tz_t *) span_alloc(sizeof(*tz))) == NULL) return NULL; } memset(tz, 0, sizeof(*tz)); @@ -816,7 +817,7 @@ SPAN_DECLARE(int) tz_release(tz_t *tz) SPAN_DECLARE(int) tz_free(tz_t *tz) { if (tz) - free(tz); + span_free(tz); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/tone_detect.c b/libs/spandsp/src/tone_detect.c index 4dfea5d5bf..2865ba40d8 100644 --- a/libs/spandsp/src/tone_detect.c +++ b/libs/spandsp/src/tone_detect.c @@ -44,6 +44,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/complex.h" #include "spandsp/complex_vector_float.h" #include "spandsp/tone_detect.h" @@ -72,7 +73,7 @@ SPAN_DECLARE(goertzel_state_t *) goertzel_init(goertzel_state_t *s, { if (s == NULL) { - if ((s = (goertzel_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (goertzel_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } #if defined(SPANDSP_USE_FIXED_POINT) @@ -98,7 +99,7 @@ SPAN_DECLARE(int) goertzel_release(goertzel_state_t *s) SPAN_DECLARE(int) goertzel_free(goertzel_state_t *s) { if (s) - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/tone_generate.c b/libs/spandsp/src/tone_generate.c index 21285f6a96..be3f6854a4 100644 --- a/libs/spandsp/src/tone_generate.c +++ b/libs/spandsp/src/tone_generate.c @@ -44,6 +44,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/complex.h" #include "spandsp/dds.h" @@ -69,7 +70,7 @@ SPAN_DECLARE(tone_gen_descriptor_t *) tone_gen_descriptor_init(tone_gen_descript { if (s == NULL) { - if ((s = (tone_gen_descriptor_t *) malloc(sizeof(*s))) == NULL) + if ((s = (tone_gen_descriptor_t *) span_alloc(sizeof(*s))) == NULL) { return NULL; } @@ -114,7 +115,7 @@ SPAN_DECLARE(tone_gen_descriptor_t *) tone_gen_descriptor_init(tone_gen_descript SPAN_DECLARE(void) tone_gen_descriptor_free(tone_gen_descriptor_t *s) { - free(s); + span_free(s); } /*- End of function --------------------------------------------------------*/ @@ -220,7 +221,7 @@ SPAN_DECLARE(tone_gen_state_t *) tone_gen_init(tone_gen_state_t *s, tone_gen_des if (s == NULL) { - if ((s = (tone_gen_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (tone_gen_state_t *) span_alloc(sizeof(*s))) == NULL) { return NULL; } @@ -252,7 +253,7 @@ SPAN_DECLARE(int) tone_gen_release(tone_gen_state_t *s) SPAN_DECLARE(int) tone_gen_free(tone_gen_state_t *s) { if (s) - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/v42.c b/libs/spandsp/src/v42.c index 29255eea07..33a4573052 100644 --- a/libs/spandsp/src/v42.c +++ b/libs/spandsp/src/v42.c @@ -41,6 +41,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/bit_operations.h" #include "spandsp/async.h" @@ -1509,7 +1510,7 @@ SPAN_DECLARE(v42_state_t *) v42_init(v42_state_t *ss, if (ss == NULL) { - if ((ss = (v42_state_t *) malloc(sizeof(*ss))) == NULL) + if ((ss = (v42_state_t *) span_alloc(sizeof(*ss))) == NULL) return NULL; } memset(ss, 0, sizeof(*ss)); @@ -1564,7 +1565,7 @@ SPAN_DECLARE(int) v42_release(v42_state_t *s) SPAN_DECLARE(int) v42_free(v42_state_t *s) { v42_release(s); - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/v42bis.c b/libs/spandsp/src/v42bis.c index fec129a6f2..cc34c54be9 100644 --- a/libs/spandsp/src/v42bis.c +++ b/libs/spandsp/src/v42bis.c @@ -39,6 +39,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/bit_operations.h" #include "spandsp/async.h" @@ -729,7 +730,7 @@ SPAN_DECLARE(v42bis_state_t *) v42bis_init(v42bis_state_t *s, return NULL; if (s == NULL) { - if ((s = (v42bis_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (v42bis_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -760,6 +761,7 @@ SPAN_DECLARE(int) v42bis_free(v42bis_state_t *s) { comp_exit(&s->compress); comp_exit(&s->decompress); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/v8.c b/libs/spandsp/src/v8.c index 3cf63ceacb..fb8436651c 100644 --- a/libs/spandsp/src/v8.c +++ b/libs/spandsp/src/v8.c @@ -42,6 +42,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/queue.h" #include "spandsp/async.h" @@ -1078,7 +1079,7 @@ SPAN_DECLARE(v8_state_t *) v8_init(v8_state_t *s, { if (s == NULL) { - if ((s = (v8_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (v8_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -1103,7 +1104,7 @@ SPAN_DECLARE(int) v8_free(v8_state_t *s) int ret; ret = queue_free(s->tx_queue); - free(s); + span_free(s); return ret; } /*- End of function --------------------------------------------------------*/ From 799402dd5b83853379e70c6ca42d50bb019f67a7 Mon Sep 17 00:00:00 2001 From: Steve Underwood Date: Tue, 6 Aug 2013 01:10:48 +0800 Subject: [PATCH 04/39] More movements of spandsp to the sue of custom allocation routines --- libs/spandsp/src/fsk.c | 9 +++--- libs/spandsp/src/hdlc.c | 9 +++--- libs/spandsp/src/ima_adpcm.c | 5 ++-- libs/spandsp/src/image_translate.c | 13 +++++---- libs/spandsp/src/modem_echo.c | 8 +++--- libs/spandsp/src/t31.c | 7 +++-- libs/spandsp/src/t38_core.c | 5 ++-- libs/spandsp/src/t38_gateway.c | 5 ++-- libs/spandsp/src/t38_non_ecm_buffer.c | 5 ++-- libs/spandsp/src/t38_terminal.c | 5 ++-- libs/spandsp/src/t42.c | 41 ++++++++++++++------------- libs/spandsp/src/t43.c | 14 +++++---- libs/spandsp/src/t4_t6_decode.c | 17 +++++------ libs/spandsp/src/t4_t6_encode.c | 17 +++++------ libs/spandsp/src/v17tx.c | 5 ++-- libs/spandsp/src/v18.c | 5 ++-- libs/spandsp/src/v22bis_tx.c | 5 ++-- libs/spandsp/src/v27ter_rx.c | 5 ++-- libs/spandsp/src/v27ter_tx.c | 5 ++-- libs/spandsp/src/v29rx.c | 5 ++-- libs/spandsp/src/v29tx.c | 5 ++-- 21 files changed, 109 insertions(+), 86 deletions(-) diff --git a/libs/spandsp/src/fsk.c b/libs/spandsp/src/fsk.c index 2c1d326d84..7e6619a58f 100644 --- a/libs/spandsp/src/fsk.c +++ b/libs/spandsp/src/fsk.c @@ -42,6 +42,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/complex.h" #include "spandsp/dds.h" #include "spandsp/power_meter.h" @@ -166,7 +167,7 @@ SPAN_DECLARE(fsk_tx_state_t *) fsk_tx_init(fsk_tx_state_t *s, { if (s == NULL) { - if ((s = (fsk_tx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (fsk_tx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -186,7 +187,7 @@ SPAN_DECLARE(int) fsk_tx_release(fsk_tx_state_t *s) SPAN_DECLARE(int) fsk_tx_free(fsk_tx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ @@ -328,7 +329,7 @@ SPAN_DECLARE(fsk_rx_state_t *) fsk_rx_init(fsk_rx_state_t *s, { if (s == NULL) { - if ((s = (fsk_rx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (fsk_rx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -348,7 +349,7 @@ SPAN_DECLARE(int) fsk_rx_release(fsk_rx_state_t *s) SPAN_DECLARE(int) fsk_rx_free(fsk_rx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/hdlc.c b/libs/spandsp/src/hdlc.c index 7733aa8280..3efaf3810e 100644 --- a/libs/spandsp/src/hdlc.c +++ b/libs/spandsp/src/hdlc.c @@ -35,6 +35,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/async.h" #include "spandsp/crc.h" #include "spandsp/bit_operations.h" @@ -314,7 +315,7 @@ SPAN_DECLARE(hdlc_rx_state_t *) hdlc_rx_init(hdlc_rx_state_t *s, { if (s == NULL) { - if ((s = (hdlc_rx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (hdlc_rx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -350,7 +351,7 @@ SPAN_DECLARE(int) hdlc_rx_release(hdlc_rx_state_t *s) SPAN_DECLARE(int) hdlc_rx_free(hdlc_rx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ @@ -592,7 +593,7 @@ SPAN_DECLARE(hdlc_tx_state_t *) hdlc_tx_init(hdlc_tx_state_t *s, { if (s == NULL) { - if ((s = (hdlc_tx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (hdlc_tx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -624,7 +625,7 @@ SPAN_DECLARE(int) hdlc_tx_release(hdlc_tx_state_t *s) SPAN_DECLARE(int) hdlc_tx_free(hdlc_tx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/ima_adpcm.c b/libs/spandsp/src/ima_adpcm.c index 6c4cc16370..fbd59df621 100644 --- a/libs/spandsp/src/ima_adpcm.c +++ b/libs/spandsp/src/ima_adpcm.c @@ -42,6 +42,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/saturated.h" #include "spandsp/ima_adpcm.h" @@ -282,7 +283,7 @@ SPAN_DECLARE(ima_adpcm_state_t *) ima_adpcm_init(ima_adpcm_state_t *s, { if (s == NULL) { - if ((s = (ima_adpcm_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (ima_adpcm_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } /*endif*/ @@ -301,7 +302,7 @@ SPAN_DECLARE(int) ima_adpcm_release(ima_adpcm_state_t *s) SPAN_DECLARE(int) ima_adpcm_free(ima_adpcm_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/image_translate.c b/libs/spandsp/src/image_translate.c index b504ca9074..ef30f6f4d4 100644 --- a/libs/spandsp/src/image_translate.c +++ b/libs/spandsp/src/image_translate.c @@ -52,6 +52,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/logging.h" #include "spandsp/saturated.h" @@ -712,7 +713,7 @@ SPAN_DECLARE(int) image_translate_restart(image_translate_state_t *s, int input_ { if (s->raw_pixel_row[i] == NULL) { - if ((s->raw_pixel_row[i] = (uint8_t *) malloc(raw_row_size)) == NULL) + if ((s->raw_pixel_row[i] = (uint8_t *) span_alloc(raw_row_size)) == NULL) return -1; } memset(s->raw_pixel_row[i], 0, raw_row_size); @@ -729,7 +730,7 @@ SPAN_DECLARE(int) image_translate_restart(image_translate_state_t *s, int input_ { if (s->pixel_row[i] == NULL) { - if ((s->pixel_row[i] = (uint8_t *) malloc(raw_row_size)) == NULL) + if ((s->pixel_row[i] = (uint8_t *) span_alloc(raw_row_size)) == NULL) return -1; } memset(s->pixel_row[i], 0, raw_row_size); @@ -757,7 +758,7 @@ SPAN_DECLARE(image_translate_state_t *) image_translate_init(image_translate_sta { if (s == NULL) { - if ((s = (image_translate_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (image_translate_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -794,12 +795,12 @@ SPAN_DECLARE(int) image_translate_release(image_translate_state_t *s) { if (s->raw_pixel_row[i]) { - free(s->raw_pixel_row[i]); + span_free(s->raw_pixel_row[i]); s->raw_pixel_row[i] = NULL; } if (s->pixel_row[i]) { - free(s->pixel_row[i]); + span_free(s->pixel_row[i]); s->pixel_row[i] = NULL; } } @@ -812,7 +813,7 @@ SPAN_DECLARE(int) image_translate_free(image_translate_state_t *s) int res; res = image_translate_release(s); - free(s); + span_free(s); return res; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/modem_echo.c b/libs/spandsp/src/modem_echo.c index 59bf57b544..622c201279 100644 --- a/libs/spandsp/src/modem_echo.c +++ b/libs/spandsp/src/modem_echo.c @@ -57,9 +57,9 @@ SPAN_DECLARE(void) modem_echo_can_free(modem_echo_can_state_t *ec) { fir16_free(&ec->fir_state); - free(ec->fir_taps32); - free(ec->fir_taps16); - free(ec); + span_free(ec->fir_taps32); + span_free(ec->fir_taps16); + span_free(ec); } /*- End of function --------------------------------------------------------*/ @@ -74,7 +74,7 @@ SPAN_DECLARE(modem_echo_can_state_t *) modem_echo_can_init(int len) ec->curr_pos = ec->taps - 1; if ((ec->fir_taps32 = (int32_t *) span_alloc(ec->taps*sizeof(int32_t))) == NULL) { - free(ec); + span_free(ec); return NULL; } memset(ec->fir_taps32, 0, ec->taps*sizeof(int32_t)); diff --git a/libs/spandsp/src/t31.c b/libs/spandsp/src/t31.c index 6a9f08d382..9993a7a521 100644 --- a/libs/spandsp/src/t31.c +++ b/libs/spandsp/src/t31.c @@ -51,6 +51,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/bit_operations.h" #include "spandsp/bitstream.h" @@ -3016,7 +3017,7 @@ SPAN_DECLARE(t31_state_t *) t31_init(t31_state_t *s, alloced = FALSE; if (s == NULL) { - if ((s = (t31_state_t *) malloc(sizeof (*s))) == NULL) + if ((s = (t31_state_t *) span_alloc(sizeof (*s))) == NULL) return NULL; /*endif*/ alloced = TRUE; @@ -3071,7 +3072,7 @@ SPAN_DECLARE(t31_state_t *) t31_init(t31_state_t *s, if ((s->rx_queue = queue_init(NULL, 4096, QUEUE_WRITE_ATOMIC | QUEUE_READ_ATOMIC)) == NULL) { if (alloced) - free(s); + span_free(s); /*endif*/ return NULL; } @@ -3100,7 +3101,7 @@ SPAN_DECLARE(int) t31_release(t31_state_t *s) SPAN_DECLARE(int) t31_free(t31_state_t *s) { t31_release(s); - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/t38_core.c b/libs/spandsp/src/t38_core.c index ae6526f7e8..922e8a372a 100644 --- a/libs/spandsp/src/t38_core.c +++ b/libs/spandsp/src/t38_core.c @@ -47,6 +47,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/bit_operations.h" #include "spandsp/t38_core.h" @@ -1109,7 +1110,7 @@ SPAN_DECLARE(t38_core_state_t *) t38_core_init(t38_core_state_t *s, { if (s == NULL) { - if ((s = (t38_core_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t38_core_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -1157,7 +1158,7 @@ SPAN_DECLARE(int) t38_core_release(t38_core_state_t *s) SPAN_DECLARE(int) t38_core_free(t38_core_state_t *s) { if (s) - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/t38_gateway.c b/libs/spandsp/src/t38_gateway.c index 7656332e80..7078a37908 100644 --- a/libs/spandsp/src/t38_gateway.c +++ b/libs/spandsp/src/t38_gateway.c @@ -50,6 +50,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/queue.h" #include "spandsp/dc_restore.h" @@ -2267,7 +2268,7 @@ SPAN_DECLARE(t38_gateway_state_t *) t38_gateway_init(t38_gateway_state_t *s, /*endif*/ if (s == NULL) { - if ((s = (t38_gateway_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t38_gateway_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; /*endif*/ } @@ -2332,7 +2333,7 @@ SPAN_DECLARE(int) t38_gateway_release(t38_gateway_state_t *s) SPAN_DECLARE(int) t38_gateway_free(t38_gateway_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/t38_non_ecm_buffer.c b/libs/spandsp/src/t38_non_ecm_buffer.c index cc339a0581..bd63c419f2 100644 --- a/libs/spandsp/src/t38_non_ecm_buffer.c +++ b/libs/spandsp/src/t38_non_ecm_buffer.c @@ -46,6 +46,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/queue.h" #include "spandsp/dc_restore.h" @@ -351,7 +352,7 @@ SPAN_DECLARE(t38_non_ecm_buffer_state_t *) t38_non_ecm_buffer_init(t38_non_ecm_b { if (s == NULL) { - if ((s = (t38_non_ecm_buffer_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t38_non_ecm_buffer_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -371,7 +372,7 @@ SPAN_DECLARE(int) t38_non_ecm_buffer_release(t38_non_ecm_buffer_state_t *s) SPAN_DECLARE(int) t38_non_ecm_buffer_free(t38_non_ecm_buffer_state_t *s) { if (s) - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/t38_terminal.c b/libs/spandsp/src/t38_terminal.c index 66938d8d24..02a9369f35 100644 --- a/libs/spandsp/src/t38_terminal.c +++ b/libs/spandsp/src/t38_terminal.c @@ -46,6 +46,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/bit_operations.h" #include "spandsp/queue.h" @@ -1525,7 +1526,7 @@ SPAN_DECLARE(t38_terminal_state_t *) t38_terminal_init(t38_terminal_state_t *s, if (s == NULL) { - if ((s = (t38_terminal_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t38_terminal_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; /*endif*/ } @@ -1564,7 +1565,7 @@ SPAN_DECLARE(int) t38_terminal_release(t38_terminal_state_t *s) SPAN_DECLARE(int) t38_terminal_free(t38_terminal_state_t *s) { t38_terminal_release(s); - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/t42.c b/libs/spandsp/src/t42.c index 8d0023f7d7..5a00a4121e 100644 --- a/libs/spandsp/src/t42.c +++ b/libs/spandsp/src/t42.c @@ -50,6 +50,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/logging.h" #include "spandsp/saturated.h" @@ -742,7 +743,7 @@ static int t42_srgb_to_itulab_jpeg(t42_encode_state_t *s) span_log(&s->logging, SPAN_LOG_FLOW, "Unspecified libjpeg error.\n"); if (s->scan_line_out) { - free(s->scan_line_out); + span_free(s->scan_line_out); s->scan_line_out = NULL; } if (s->out) @@ -802,12 +803,12 @@ static int t42_srgb_to_itulab_jpeg(t42_encode_state_t *s) set_itu_fax(s); - if ((s->scan_line_in = (JSAMPROW) malloc(s->samples_per_pixel*s->image_width)) == NULL) + if ((s->scan_line_in = (JSAMPROW) span_alloc(s->samples_per_pixel*s->image_width)) == NULL) return -1; if (s->image_type == T4_IMAGE_TYPE_COLOUR_8BIT) { - if ((s->scan_line_out = (JSAMPROW) malloc(s->samples_per_pixel*s->image_width)) == NULL) + if ((s->scan_line_out = (JSAMPROW) span_alloc(s->samples_per_pixel*s->image_width)) == NULL) return -1; for (i = 0; i < s->compressor.image_height; i++) @@ -828,7 +829,7 @@ static int t42_srgb_to_itulab_jpeg(t42_encode_state_t *s) if (s->scan_line_out) { - free(s->scan_line_out); + span_free(s->scan_line_out); s->scan_line_out = NULL; } jpeg_finish_compress(&s->compressor); @@ -841,13 +842,13 @@ static int t42_srgb_to_itulab_jpeg(t42_encode_state_t *s) #else s->buf_size = s->compressed_image_size = ftell(s->out); - if ((s->compressed_buf = malloc(s->compressed_image_size)) == NULL) + if ((s->compressed_buf = span_alloc(s->compressed_image_size)) == NULL) return -1; if (fseek(s->out, 0, SEEK_SET) != 0) { fclose(s->out); s->out = NULL; - free(s->compressed_buf); + span_free(s->compressed_buf); s->compressed_buf = NULL; return -1; } @@ -855,7 +856,7 @@ static int t42_srgb_to_itulab_jpeg(t42_encode_state_t *s) { fclose(s->out); s->out = NULL; - free(s->compressed_buf); + span_free(s->compressed_buf); s->compressed_buf = NULL; return -1; } @@ -986,7 +987,7 @@ SPAN_DECLARE(t42_encode_state_t *) t42_encode_init(t42_encode_state_t *s, { if (s == NULL) { - if ((s = (t42_encode_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t42_encode_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -1016,7 +1017,7 @@ SPAN_DECLARE(int) t42_encode_free(t42_encode_state_t *s) int ret; ret = t42_encode_release(s); - free(s); + span_free(s); return ret; } /*- End of function --------------------------------------------------------*/ @@ -1087,7 +1088,7 @@ static int t42_itulab_jpeg_to_srgb(t42_decode_state_t *s) span_log(&s->logging, SPAN_LOG_FLOW, "Unspecified libjpeg error.\n"); if (s->scan_line_out) { - free(s->scan_line_out); + span_free(s->scan_line_out); s->scan_line_out = NULL; } if (s->in) @@ -1155,12 +1156,12 @@ static int t42_itulab_jpeg_to_srgb(t42_decode_state_t *s) jpeg_start_decompress(&s->decompressor); - if ((s->scan_line_in = malloc(s->samples_per_pixel*s->image_width)) == NULL) + if ((s->scan_line_in = span_alloc(s->samples_per_pixel*s->image_width)) == NULL) return -1; if (s->samples_per_pixel == 3) { - if ((s->scan_line_out = malloc(s->samples_per_pixel*s->image_width)) == NULL) + if ((s->scan_line_out = span_alloc(s->samples_per_pixel*s->image_width)) == NULL) return -1; while (s->decompressor.output_scanline < s->image_length) @@ -1181,12 +1182,12 @@ static int t42_itulab_jpeg_to_srgb(t42_decode_state_t *s) if (s->scan_line_in) { - free(s->scan_line_in); + span_free(s->scan_line_in); s->scan_line_in = NULL; } if (s->scan_line_out) { - free(s->scan_line_out); + span_free(s->scan_line_out); s->scan_line_out = NULL; } jpeg_finish_decompress(&s->decompressor); @@ -1243,7 +1244,7 @@ SPAN_DECLARE(int) t42_decode_put(t42_decode_state_t *s, const uint8_t data[], si if (s->compressed_image_size + len > s->buf_size) { - if ((buf = (uint8_t *) realloc(s->compressed_buf, s->compressed_image_size + len + 10000)) == NULL) + if ((buf = (uint8_t *) span_realloc(s->compressed_buf, s->compressed_image_size + len + 10000)) == NULL) return -1; s->buf_size = s->compressed_image_size + len + 10000; s->compressed_buf = buf; @@ -1340,7 +1341,7 @@ SPAN_DECLARE(t42_decode_state_t *) t42_decode_init(t42_decode_state_t *s, { if (s == NULL) { - if ((s = (t42_decode_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t42_decode_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -1363,12 +1364,12 @@ SPAN_DECLARE(int) t42_decode_release(t42_decode_state_t *s) { if (s->scan_line_in) { - free(s->scan_line_in); + span_free(s->scan_line_in); s->scan_line_in = NULL; } if (s->scan_line_out) { - free(s->scan_line_out); + span_free(s->scan_line_out); s->scan_line_out = NULL; } jpeg_destroy_decompress(&s->decompressor); @@ -1379,7 +1380,7 @@ SPAN_DECLARE(int) t42_decode_release(t42_decode_state_t *s) } if (s->comment) { - free(s->comment); + span_free(s->comment); s->comment = NULL; } return 0; @@ -1391,7 +1392,7 @@ SPAN_DECLARE(int) t42_decode_free(t42_decode_state_t *s) int ret; ret = t42_decode_release(s); - free(s); + span_free(s); return ret; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/t43.c b/libs/spandsp/src/t43.c index b0e1abffb9..9e2ee76be2 100644 --- a/libs/spandsp/src/t43.c +++ b/libs/spandsp/src/t43.c @@ -44,6 +44,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/async.h" #include "spandsp/timezone.h" @@ -133,7 +134,9 @@ static int t43_create_header(t43_encode_state_t *s, uint8_t data[], size_t len) { int pos; int val[6]; +#if 0 int bytes_per_entry; +#endif pos = 0; unpack_16(data, 0xFFA8); @@ -345,7 +348,7 @@ SPAN_DECLARE(t43_encode_state_t *) t43_encode_init(t43_encode_state_t *s, { if (s == NULL) { - if ((s = (t43_encode_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t43_encode_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -380,7 +383,7 @@ SPAN_DECLARE(int) t43_encode_free(t43_encode_state_t *s) t85_encode_free(&s->t85); ret = t43_encode_release(s); - free(s); + span_free(s); return ret; } /*- End of function --------------------------------------------------------*/ @@ -700,7 +703,7 @@ static int t85_row_write_handler(void *user_data, const uint8_t buf[], size_t le if (s->buf == NULL) { image_size = s->samples_per_pixel*s->t85.xd*s->t85.yd; - if ((s->buf = malloc(image_size)) == NULL) + if ((s->buf = span_alloc(image_size)) == NULL) return -1; memset(s->buf, 0, image_size); } @@ -761,6 +764,7 @@ SPAN_DECLARE(int) t43_decode_put(t43_decode_state_t *s, const uint8_t data[], si } /* Now deal the bit-planes, one after another. */ + total_len = 0; while (s->current_bit_plane < s->t85.bit_planes) { j = s->current_bit_plane; @@ -882,7 +886,7 @@ SPAN_DECLARE(t43_decode_state_t *) t43_decode_init(t43_decode_state_t *s, { if (s == NULL) { - if ((s = (t43_decode_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t43_decode_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -922,7 +926,7 @@ SPAN_DECLARE(int) t43_decode_free(t43_decode_state_t *s) ret = t43_decode_release(s); t85_decode_free(&s->t85); - free(s); + span_free(s); return ret; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/t4_t6_decode.c b/libs/spandsp/src/t4_t6_decode.c index c347dfd19a..219a0bafb8 100644 --- a/libs/spandsp/src/t4_t6_decode.c +++ b/libs/spandsp/src/t4_t6_decode.c @@ -79,6 +79,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/bit_operations.h" #include "spandsp/async.h" @@ -138,17 +139,17 @@ static int free_buffers(t4_t6_decode_state_t *s) { if (s->cur_runs) { - free(s->cur_runs); + span_free(s->cur_runs); s->cur_runs = NULL; } if (s->ref_runs) { - free(s->ref_runs); + span_free(s->ref_runs); s->ref_runs = NULL; } if (s->row_buf) { - free(s->row_buf); + span_free(s->row_buf); s->row_buf = NULL; } s->bytes_per_row = 0; @@ -824,10 +825,10 @@ SPAN_DECLARE(int) t4_t6_decode_restart(t4_t6_decode_state_t *s, int image_width) if (s->bytes_per_row == 0 || image_width != s->image_width) { /* Allocate the space required for decoding the new row length. */ - if ((bufptr = (uint32_t *) realloc(s->cur_runs, run_space)) == NULL) + if ((bufptr = (uint32_t *) span_realloc(s->cur_runs, run_space)) == NULL) return -1; s->cur_runs = bufptr; - if ((bufptr = (uint32_t *) realloc(s->ref_runs, run_space)) == NULL) + if ((bufptr = (uint32_t *) span_realloc(s->ref_runs, run_space)) == NULL) return -1; s->ref_runs = bufptr; s->image_width = image_width; @@ -835,7 +836,7 @@ SPAN_DECLARE(int) t4_t6_decode_restart(t4_t6_decode_state_t *s, int image_width) bytes_per_row = (image_width + 7)/8; if (bytes_per_row != s->bytes_per_row) { - if ((bufptr8 = (uint8_t *) realloc(s->row_buf, bytes_per_row)) == NULL) + if ((bufptr8 = (uint8_t *) span_realloc(s->row_buf, bytes_per_row)) == NULL) return -1; s->row_buf = bufptr8; s->bytes_per_row = bytes_per_row; @@ -892,7 +893,7 @@ SPAN_DECLARE(t4_t6_decode_state_t *) t4_t6_decode_init(t4_t6_decode_state_t *s, { if (s == NULL) { - if ((s = (t4_t6_decode_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t4_t6_decode_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -919,7 +920,7 @@ SPAN_DECLARE(int) t4_t6_decode_free(t4_t6_decode_state_t *s) int ret; ret = t4_t6_decode_release(s); - free(s); + span_free(s); return ret; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/t4_t6_encode.c b/libs/spandsp/src/t4_t6_encode.c index 4ed063e063..fde78f4827 100644 --- a/libs/spandsp/src/t4_t6_encode.c +++ b/libs/spandsp/src/t4_t6_encode.c @@ -76,6 +76,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/bit_operations.h" #include "spandsp/async.h" @@ -373,17 +374,17 @@ static int free_buffers(t4_t6_encode_state_t *s) { if (s->cur_runs) { - free(s->cur_runs); + span_free(s->cur_runs); s->cur_runs = NULL; } if (s->ref_runs) { - free(s->ref_runs); + span_free(s->ref_runs); s->ref_runs = NULL; } if (s->bitstream) { - free(s->bitstream); + span_free(s->bitstream); s->bitstream = NULL; } s->bytes_per_row = 0; @@ -1026,13 +1027,13 @@ SPAN_DECLARE(int) t4_t6_encode_set_image_width(t4_t6_encode_state_t *s, int imag s->bytes_per_row = (s->image_width + 7)/8; run_space = (s->image_width + 4)*sizeof(uint32_t); - if ((bufptr = (uint32_t *) realloc(s->cur_runs, run_space)) == NULL) + if ((bufptr = (uint32_t *) span_realloc(s->cur_runs, run_space)) == NULL) return -1; s->cur_runs = bufptr; - if ((bufptr = (uint32_t *) realloc(s->ref_runs, run_space)) == NULL) + if ((bufptr = (uint32_t *) span_realloc(s->ref_runs, run_space)) == NULL) return -1; s->ref_runs = bufptr; - if ((bufptr8 = (uint8_t *) realloc(s->bitstream, (s->image_width + 1)*sizeof(uint16_t))) == NULL) + if ((bufptr8 = (uint8_t *) span_realloc(s->bitstream, (s->image_width + 1)*sizeof(uint16_t))) == NULL) return -1; s->bitstream = bufptr8; } @@ -1151,7 +1152,7 @@ SPAN_DECLARE(t4_t6_encode_state_t *) t4_t6_encode_init(t4_t6_encode_state_t *s, { if (s == NULL) { - if ((s = (t4_t6_encode_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t4_t6_encode_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -1181,7 +1182,7 @@ SPAN_DECLARE(int) t4_t6_encode_free(t4_t6_encode_state_t *s) int ret; ret = t4_t6_encode_release(s); - free(s); + span_free(s); return ret; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/v17tx.c b/libs/spandsp/src/v17tx.c index fe361d7744..b4f9f3e80a 100644 --- a/libs/spandsp/src/v17tx.c +++ b/libs/spandsp/src/v17tx.c @@ -42,6 +42,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/logging.h" #include "spandsp/complex.h" @@ -449,7 +450,7 @@ SPAN_DECLARE(v17_tx_state_t *) v17_tx_init(v17_tx_state_t *s, int bit_rate, int } if (s == NULL) { - if ((s = (v17_tx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (v17_tx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -473,7 +474,7 @@ SPAN_DECLARE(int) v17_tx_release(v17_tx_state_t *s) SPAN_DECLARE(int) v17_tx_free(v17_tx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/v18.c b/libs/spandsp/src/v18.c index 65783eb73b..177ca88229 100644 --- a/libs/spandsp/src/v18.c +++ b/libs/spandsp/src/v18.c @@ -43,6 +43,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/queue.h" #include "spandsp/async.h" @@ -1113,7 +1114,7 @@ SPAN_DECLARE(v18_state_t *) v18_init(v18_state_t *s, if (s == NULL) { - if ((s = (v18_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (v18_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -1204,7 +1205,7 @@ SPAN_DECLARE(int) v18_release(v18_state_t *s) SPAN_DECLARE(int) v18_free(v18_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/v22bis_tx.c b/libs/spandsp/src/v22bis_tx.c index bb18b77b26..d7ecbe269a 100644 --- a/libs/spandsp/src/v22bis_tx.c +++ b/libs/spandsp/src/v22bis_tx.c @@ -45,6 +45,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/logging.h" #include "spandsp/complex.h" @@ -700,7 +701,7 @@ SPAN_DECLARE(v22bis_state_t *) v22bis_init(v22bis_state_t *s, } if (s == NULL) { - if ((s = (v22bis_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (v22bis_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -748,7 +749,7 @@ SPAN_DECLARE(int) v22bis_release(v22bis_state_t *s) SPAN_DECLARE(int) v22bis_free(v22bis_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/v27ter_rx.c b/libs/spandsp/src/v27ter_rx.c index 5dabe1c6f0..0e49cf901b 100644 --- a/libs/spandsp/src/v27ter_rx.c +++ b/libs/spandsp/src/v27ter_rx.c @@ -43,6 +43,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/fast_convert.h" #include "spandsp/math_fixed.h" @@ -1087,7 +1088,7 @@ SPAN_DECLARE(v27ter_rx_state_t *) v27ter_rx_init(v27ter_rx_state_t *s, int bit_r } if (s == NULL) { - if ((s = (v27ter_rx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (v27ter_rx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -1110,7 +1111,7 @@ SPAN_DECLARE(int) v27ter_rx_release(v27ter_rx_state_t *s) SPAN_DECLARE(int) v27ter_rx_free(v27ter_rx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/v27ter_tx.c b/libs/spandsp/src/v27ter_tx.c index f1d7ce263d..1195b96d8f 100644 --- a/libs/spandsp/src/v27ter_tx.c +++ b/libs/spandsp/src/v27ter_tx.c @@ -42,6 +42,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/logging.h" #include "spandsp/complex.h" @@ -404,7 +405,7 @@ SPAN_DECLARE(v27ter_tx_state_t *) v27ter_tx_init(v27ter_tx_state_t *s, int bit_r } if (s == NULL) { - if ((s = (v27ter_tx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (v27ter_tx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -427,7 +428,7 @@ SPAN_DECLARE(int) v27ter_tx_release(v27ter_tx_state_t *s) SPAN_DECLARE(int) v27ter_tx_free(v27ter_tx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/v29rx.c b/libs/spandsp/src/v29rx.c index 3bb476726d..a5520e92cd 100644 --- a/libs/spandsp/src/v29rx.c +++ b/libs/spandsp/src/v29rx.c @@ -43,6 +43,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/fast_convert.h" #include "spandsp/math_fixed.h" @@ -1148,7 +1149,7 @@ SPAN_DECLARE(v29_rx_state_t *) v29_rx_init(v29_rx_state_t *s, int bit_rate, put_ } if (s == NULL) { - if ((s = (v29_rx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (v29_rx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -1176,7 +1177,7 @@ SPAN_DECLARE(int) v29_rx_release(v29_rx_state_t *s) SPAN_DECLARE(int) v29_rx_free(v29_rx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/v29tx.c b/libs/spandsp/src/v29tx.c index 3eac97e1bc..d6dbedf9ce 100644 --- a/libs/spandsp/src/v29tx.c +++ b/libs/spandsp/src/v29tx.c @@ -42,6 +42,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/fast_convert.h" #include "spandsp/logging.h" #include "spandsp/complex.h" @@ -388,7 +389,7 @@ SPAN_DECLARE(v29_tx_state_t *) v29_tx_init(v29_tx_state_t *s, int bit_rate, int } if (s == NULL) { - if ((s = (v29_tx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (v29_tx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -411,7 +412,7 @@ SPAN_DECLARE(int) v29_tx_release(v29_tx_state_t *s) SPAN_DECLARE(int) v29_tx_free(v29_tx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ From 13e8532398350866d1d57b943d0cb605e8df632e Mon Sep 17 00:00:00 2001 From: Steve Underwood Date: Tue, 6 Aug 2013 01:17:05 +0800 Subject: [PATCH 05/39] Hopefully all the spandsp functions now use custom allocation routines --- libs/spandsp/src/t30.c | 39 ++++++++++++++++++++------------------- libs/spandsp/src/t4_rx.c | 3 ++- libs/spandsp/src/t4_tx.c | 13 +++++++------ libs/spandsp/src/v17rx.c | 5 +++-- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/libs/spandsp/src/t30.c b/libs/spandsp/src/t30.c index 1e3107b0b2..484b627a2b 100644 --- a/libs/spandsp/src/t30.c +++ b/libs/spandsp/src/t30.c @@ -45,6 +45,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/bit_operations.h" #include "spandsp/queue.h" @@ -636,89 +637,89 @@ static void release_resources(t30_state_t *s) { if (s->tx_info.nsf) { - free(s->tx_info.nsf); + span_free(s->tx_info.nsf); s->tx_info.nsf = NULL; } s->tx_info.nsf_len = 0; if (s->tx_info.nsc) { - free(s->tx_info.nsc); + span_free(s->tx_info.nsc); s->tx_info.nsc = NULL; } s->tx_info.nsc_len = 0; if (s->tx_info.nss) { - free(s->tx_info.nss); + span_free(s->tx_info.nss); s->tx_info.nss = NULL; } s->tx_info.nss_len = 0; if (s->tx_info.tsa) { - free(s->tx_info.tsa); + span_free(s->tx_info.tsa); s->tx_info.tsa = NULL; } if (s->tx_info.ira) { - free(s->tx_info.ira); + span_free(s->tx_info.ira); s->tx_info.ira = NULL; } if (s->tx_info.cia) { - free(s->tx_info.cia); + span_free(s->tx_info.cia); s->tx_info.cia = NULL; } if (s->tx_info.isp) { - free(s->tx_info.isp); + span_free(s->tx_info.isp); s->tx_info.isp = NULL; } if (s->tx_info.csa) { - free(s->tx_info.csa); + span_free(s->tx_info.csa); s->tx_info.csa = NULL; } if (s->rx_info.nsf) { - free(s->rx_info.nsf); + span_free(s->rx_info.nsf); s->rx_info.nsf = NULL; } s->rx_info.nsf_len = 0; if (s->rx_info.nsc) { - free(s->rx_info.nsc); + span_free(s->rx_info.nsc); s->rx_info.nsc = NULL; } s->rx_info.nsc_len = 0; if (s->rx_info.nss) { - free(s->rx_info.nss); + span_free(s->rx_info.nss); s->rx_info.nss = NULL; } s->rx_info.nss_len = 0; if (s->rx_info.tsa) { - free(s->rx_info.tsa); + span_free(s->rx_info.tsa); s->rx_info.tsa = NULL; } if (s->rx_info.ira) { - free(s->rx_info.ira); + span_free(s->rx_info.ira); s->rx_info.ira = NULL; } if (s->rx_info.cia) { - free(s->rx_info.cia); + span_free(s->rx_info.cia); s->rx_info.cia = NULL; } if (s->rx_info.isp) { - free(s->rx_info.isp); + span_free(s->rx_info.isp); s->rx_info.isp = NULL; } if (s->rx_info.csa) { - free(s->rx_info.csa); + span_free(s->rx_info.csa); s->rx_info.csa = NULL; } } @@ -5829,7 +5830,7 @@ static int decode_nsf_nss_nsc(t30_state_t *s, uint8_t *msg[], const uint8_t *pkt { uint8_t *t; - if ((t = malloc(len - 1)) == NULL) + if ((t = span_alloc(len - 1)) == NULL) return 0; memcpy(t, pkt + 1, len - 1); *msg = t; @@ -6795,7 +6796,7 @@ SPAN_DECLARE(t30_state_t *) t30_init(t30_state_t *s, { if (s == NULL) { - if ((s = (t30_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t30_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -6845,7 +6846,7 @@ SPAN_DECLARE(int) t30_release(t30_state_t *s) SPAN_DECLARE(int) t30_free(t30_state_t *s) { t30_release(s); - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/t4_rx.c b/libs/spandsp/src/t4_rx.c index 616452a406..5a7bb6bc45 100644 --- a/libs/spandsp/src/t4_rx.c +++ b/libs/spandsp/src/t4_rx.c @@ -48,6 +48,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/bit_operations.h" #include "spandsp/async.h" @@ -1121,7 +1122,7 @@ SPAN_DECLARE(t4_rx_state_t *) t4_rx_init(t4_rx_state_t *s, const char *file, int allocated = FALSE; if (s == NULL) { - if ((s = (t4_rx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t4_rx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; allocated = TRUE; } diff --git a/libs/spandsp/src/t4_tx.c b/libs/spandsp/src/t4_tx.c index 3419894c64..9e8f3e678c 100644 --- a/libs/spandsp/src/t4_tx.c +++ b/libs/spandsp/src/t4_tx.c @@ -48,6 +48,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/bit_operations.h" #include "spandsp/async.h" @@ -621,7 +622,7 @@ static int read_tiff_t85_image(t4_tx_state_t *s) if (len > biggest) biggest = len; } - if ((raw_data = malloc(biggest)) == NULL) + if ((raw_data = span_alloc(biggest)) == NULL) return -1; s->tiff.image_size = s->tiff.image_length*((s->tiff.image_width + 7)/8); @@ -685,7 +686,7 @@ static int read_tiff_t43_image(t4_tx_state_t *s, uint8_t **buf) total_image_len = 0; for (i = 0; i < num_strips; i++) total_image_len += TIFFRawStripSize(s->tiff.tiff_file, i); - if ((raw_data = malloc(total_image_len)) == NULL) + if ((raw_data = span_alloc(total_image_len)) == NULL) return -1; total_len = 0; @@ -704,7 +705,7 @@ static int read_tiff_t43_image(t4_tx_state_t *s, uint8_t **buf) span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); image_size = 3*s->metadata.image_length*s->metadata.image_width; - if ((*buf = malloc(image_size)) == NULL) + if ((*buf = span_alloc(image_size)) == NULL) return -1; pack.buf = *buf; @@ -751,7 +752,7 @@ static int read_tiff_t42_t81_image(t4_tx_state_t *s) for (i = 0; i < num_strips; i++) total_image_len += TIFFRawStripSize(s->tiff.tiff_file, i); - if ((raw_data = malloc(total_image_len)) == NULL) + if ((raw_data = span_alloc(total_image_len)) == NULL) return -1; total_len = 0; @@ -985,7 +986,7 @@ static int make_header(t4_tx_state_t *s) if (s->header_text == NULL) { - if ((s->header_text = malloc(132 + 1)) == NULL) + if ((s->header_text = span_alloc(132 + 1)) == NULL) return -1; } /* This is very English oriented, but then most FAX machines are, too. Some @@ -1604,7 +1605,7 @@ SPAN_DECLARE(t4_tx_state_t *) t4_tx_init(t4_tx_state_t *s, const char *file, int allocated = FALSE; if (s == NULL) { - if ((s = (t4_tx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (t4_tx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; allocated = TRUE; } diff --git a/libs/spandsp/src/v17rx.c b/libs/spandsp/src/v17rx.c index 256d71a14c..a1d9585983 100644 --- a/libs/spandsp/src/v17rx.c +++ b/libs/spandsp/src/v17rx.c @@ -43,6 +43,7 @@ #include "floating_fudge.h" #include "spandsp/telephony.h" +#include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/fast_convert.h" #include "spandsp/math_fixed.h" @@ -1526,7 +1527,7 @@ SPAN_DECLARE(v17_rx_state_t *) v17_rx_init(v17_rx_state_t *s, int bit_rate, put_ } if (s == NULL) { - if ((s = (v17_rx_state_t *) malloc(sizeof(*s))) == NULL) + if ((s = (v17_rx_state_t *) span_alloc(sizeof(*s))) == NULL) return NULL; } memset(s, 0, sizeof(*s)); @@ -1551,7 +1552,7 @@ SPAN_DECLARE(int) v17_rx_release(v17_rx_state_t *s) SPAN_DECLARE(int) v17_rx_free(v17_rx_state_t *s) { - free(s); + span_free(s); return 0; } /*- End of function --------------------------------------------------------*/ From df669f700ae685f19cd8a569882066139898513e Mon Sep 17 00:00:00 2001 From: Steve Underwood Date: Tue, 6 Aug 2013 02:38:06 +0800 Subject: [PATCH 06/39] A cleanup of FAX image size/resolution matching accuracy. Squashing of bi-level images should now be correct. This is now close to supporting grey scale and colour. --- libs/spandsp/INSTALL | 397 ++++--- libs/spandsp/spandsp-sim/Makefile.am | 2 +- libs/spandsp/src/Makefile.am | 2 +- libs/spandsp/src/spandsp/t4_tx.h | 17 - libs/spandsp/src/t30.c | 414 +++---- libs/spandsp/src/t4_rx.c | 254 +++-- libs/spandsp/src/t4_tx.c | 1457 ++++++++++++++++++++---- libs/spandsp/tests/Makefile.am | 2 +- libs/spandsp/tests/regression_tests.sh | 9 + libs/spandsp/tests/t31_tests.c | 4 +- libs/spandsp/tests/t4_tests.c | 3 - libs/spandsp/tests/tsb85_tests.c | 65 +- 12 files changed, 1860 insertions(+), 766 deletions(-) diff --git a/libs/spandsp/INSTALL b/libs/spandsp/INSTALL index 2abc70492a..007e9396d0 100644 --- a/libs/spandsp/INSTALL +++ b/libs/spandsp/INSTALL @@ -1,121 +1,80 @@ -Building and installing spandsp -=============================== - -A number of distributions include spandsp, but they usually use older versions -of the library, which lack a lot of the features of the current version. Before -installing spandsp, make sure there are no older versions already on your -machine. Make sure libtiff is installed on your machine. Versions 3.5.7, -3.6.0, 3.7.1 and 3.8.2 seem to work OK. There have been several bugs related -to FAX document handling in some versions of libtiff. Also, some people have -had trouble using spandsp because they had more than one version of libtiff -on their machine. Take care with this. If you are using an RPM based system, -such as RedHat or Fedora, you will need the libtiff and libtiff-devel RPMs -installed to be able to build spandsp. - -You can use the usual: - - ./configure - make - make install - -process to build the spandsp library. Note that if you use configure in this -way, the software will be installed in /usr/local. In this case make sure your -/etc/ld.so.conf file has an entry for /usr/local/lib. If you wish the software -to be installed in /usr, you should build it with the commands. - - ./configure --prefix=/usr - make - make install - - -Building the programming documentation -====================================== - -If you wish to build the programming documentation for spandsp, configure -spandsp with: - - ./configure --enable-doc - -You need doxygen installed on your machine. - - -Building the test suite -======================= - -Most sections of the spandsp library have an accompanying test program in the -test directory. If you wish to build these test programs, configure spandsp -with: - - ./configure --enable-tests - -To build these tests you will need libaudiofile installed on your machine. To -build the modem tests, with the GUI monitoring feature you will need Fltk 1.1.4 -or later, an audio meter module and a cartesian plotting module. Fltk may be -obtained from http://www.fltk.org. The audio meter module may be obtained from -http://www.soft-switch.org/downloads/Fl_Audio_Meter.tgz . The cartesian plotting -module may be obtained from http://134.226.68.29/fltk. However, there is no -suitable makefile supplied with that. You can find a version at -http://www.soft-switch.org/downloads/Fl_Cartesian.tgz which will build as a -Linux library. The actual code in both these versions is identical. -You need to have Fltk 1.1.4 or later installed before building the plotting -library. - - -Applications -============ - -Applications support for spandsp is built into packages such as Callweaver, -FreeSwitch and iaxmodem. Code to add spandsp based FAX support to Asterisk may -be found at http://sourceforge.net/projects/agx-ast-addons. - +Installation Instructions +************************* +Copyright (C) 1994-1996, 1999-2002, 2004-2013 Free Software Foundation, +Inc. + Copying and distribution of this file, with or without modification, +are permitted in any medium without royalty provided the copyright +notice and this notice are preserved. This file is offered as-is, +without warranty of any kind. Basic Installation ================== - These are generic installation instructions. + Briefly, the shell commands `./configure; make; make install' should +configure, build, and install this package. The following +more-detailed instructions are generic; see the `README' file for +instructions specific to this package. Some packages provide this +`INSTALL' file but do not implement all of the features documented +below. The lack of an optional feature in a given package is not +necessarily a bug. More recommendations for GNU packages can be found +in *note Makefile Conventions: (standards)Makefile Conventions. The `configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses those values to create a `Makefile' in each directory of the package. It may also create one or more `.h' files containing system-dependent definitions. Finally, it creates a shell script `config.status' that -you can run in the future to recreate the current configuration, a file -`config.cache' that saves the results of its tests to speed up -reconfiguring, and a file `config.log' containing compiler output -(useful mainly for debugging `configure'). +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. Caching is +disabled by default to prevent problems with accidental use of stale +cache files. If you need to do unusual things to compile the package, please try to figure out how `configure' could check whether to do them, and mail diffs or instructions to the address given in the `README' so they can -be considered for the next release. If at some point `config.cache' -contains results you don't want to keep, you may remove or edit it. +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. - The file `configure.ac' is used to create `configure' by a program -called `autoconf'. You only need `configure.ac' if you want to change -it or regenerate `configure' using a newer version of `autoconf'. + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You need `configure.ac' if +you want to change it or regenerate `configure' using a newer version +of `autoconf'. -The simplest way to compile this package is: + The simplest way to compile this package is: 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. If you're - using `csh' on an old version of System V, you might need to type - `sh ./configure' instead to prevent `csh' from trying to execute - `configure' itself. + `./configure' to configure the package for your system. - Running `configure' takes awhile. While running, it prints some - messages telling which features it is checking for. + Running `configure' might take a while. While running, it prints + some messages telling which features it is checking for. 2. Type `make' to compile the package. 3. Optionally, type `make check' to run any self-tests that come with - the package. + the package, generally using the just-built uninstalled binaries. 4. Type `make install' to install the programs and any data files and - documentation. + documentation. When installing into a prefix owned by root, it is + recommended that the package be configured and built as a regular + user, and only the `make install' phase executed with root + privileges. - 5. You can remove the program binaries and object files from the + 5. Optionally, type `make installcheck' to repeat any self-tests, but + this time using the binaries in their final installed location. + This target does not install anything. Running this target as a + regular user, particularly if the prior `make install' required + root privileges, verifies that the installation completed + correctly. + + 6. You can remove the program binaries and object files from the source code directory by typing `make clean'. To also remove the files that `configure' created (so you can compile the package for a different kind of computer), type `make distclean'. There is @@ -124,62 +83,119 @@ The simplest way to compile this package is: all sorts of other programs in order to regenerate files that came with the distribution. + 7. Often, you can also type `make uninstall' to remove the installed + files again. In practice, not all packages have tested that + uninstallation works correctly, even though it is required by the + GNU Coding Standards. + + 8. Some packages, particularly those that use Automake, provide `make + distcheck', which can by used by developers to test that all other + targets like `make install' and `make uninstall' work correctly. + This target is generally not run by end users. + Compilers and Options ===================== Some systems require unusual options for compilation or linking that -the `configure' script does not know about. You can give `configure' -initial values for variables by setting them in the environment. Using -a Bourne-compatible shell, you can do that on the command line like -this: - CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure +the `configure' script does not know about. Run `./configure --help' +for details on some of the pertinent environment variables. -Or on systems that have the `env' program, you can do it like this: - env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure + You can give `configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here +is an example: + + ./configure CC=c99 CFLAGS=-g LIBS=-lposix + + *Note Defining Variables::, for more details. Compiling For Multiple Architectures ==================================== You can compile the package for more than one kind of computer at the same time, by placing the object files for each architecture in their -own directory. To do this, you must use a version of `make' that -supports the `VPATH' variable, such as GNU `make'. `cd' to the +own directory. To do this, you can use GNU `make'. `cd' to the directory where you want the object files and executables to go and run the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. +source code in the directory that `configure' is in and in `..'. This +is known as a "VPATH" build. - If you have to use a `make' that does not supports the `VPATH' -variable, you have to compile the package for one architecture at a time -in the source code directory. After you have installed the package for -one architecture, use `make distclean' before reconfiguring for another -architecture. + With a non-GNU `make', it is safer to compile the package for one +architecture at a time in the source code directory. After you have +installed the package for one architecture, use `make distclean' before +reconfiguring for another architecture. + + On MacOS X 10.5 and later systems, you can create libraries and +executables that work on multiple system types--known as "fat" or +"universal" binaries--by specifying multiple `-arch' options to the +compiler but only a single `-arch' option to the preprocessor. Like +this: + + ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ + CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ + CPP="gcc -E" CXXCPP="g++ -E" + + This is not guaranteed to produce working output in all cases, you +may have to build one architecture at a time and combine the results +using the `lipo' tool if you have problems. Installation Names ================== - By default, `make install' will install the package's files in -`/usr/local/bin', `/usr/local/man', etc. You can specify an -installation prefix other than `/usr/local' by giving `configure' the -option `--prefix=PATH'. + By default, `make install' installs the package's commands under +`/usr/local/bin', include files under `/usr/local/include', etc. You +can specify an installation prefix other than `/usr/local' by giving +`configure' the option `--prefix=PREFIX', where PREFIX must be an +absolute file name. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you -give `configure' the option `--exec-prefix=PATH', the package will use -PATH as the prefix for installing programs and libraries. -Documentation and other data files will still use the regular prefix. +pass the option `--exec-prefix=PREFIX' to `configure', the package uses +PREFIX as the prefix for installing programs and libraries. +Documentation and other data files still use the regular prefix. In addition, if you use an unusual directory layout you can give -options like `--bindir=PATH' to specify different values for particular +options like `--bindir=DIR' to specify different values for particular kinds of files. Run `configure --help' for a list of the directories -you can set and what kinds of files go in them. +you can set and what kinds of files go in them. In general, the +default for these options is expressed in terms of `${prefix}', so that +specifying just `--prefix' will affect all of the other directory +specifications that were not explicitly provided. + + The most portable way to affect installation locations is to pass the +correct locations to `configure'; however, many packages provide one or +both of the following shortcuts of passing variable assignments to the +`make install' command line to change installation locations without +having to reconfigure or recompile. + + The first method involves providing an override variable for each +affected directory. For example, `make install +prefix=/alternate/directory' will choose an alternate location for all +directory configuration variables that were expressed in terms of +`${prefix}'. Any directories that were specified during `configure', +but not in terms of `${prefix}', must each be overridden at install +time for the entire installation to be relocated. The approach of +makefile variable overrides for each directory variable is required by +the GNU Coding Standards, and ideally causes no recompilation. +However, some platforms have known limitations with the semantics of +shared libraries that end up requiring recompilation when using this +method, particularly noticeable in packages that use GNU Libtool. + + The second method involves providing the `DESTDIR' variable. For +example, `make install DESTDIR=/alternate/directory' will prepend +`/alternate/directory' before all installation names. The approach of +`DESTDIR' overrides is not required by the GNU Coding Standards, and +does not work on platforms that have drive letters. On the other hand, +it does better at avoiding recompilation issues, and works well even +when some directory options were not specified in terms of `${prefix}' +at `configure' time. + +Optional Features +================= If the package supports it, you can cause programs to be installed with an extra prefix or suffix on their names by giving `configure' the option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. -Optional Features -================= - Some packages pay attention to `--enable-FEATURE' options to `configure', where FEATURE indicates an optional part of the package. They may also pay attention to `--with-PACKAGE' options, where PACKAGE @@ -192,25 +208,80 @@ find the X include and library files automatically, but if it doesn't, you can use the `configure' options `--x-includes=DIR' and `--x-libraries=DIR' to specify their locations. + Some packages offer the ability to configure how verbose the +execution of `make' will be. For these packages, running `./configure +--enable-silent-rules' sets the default to minimal output, which can be +overridden with `make V=1'; while running `./configure +--disable-silent-rules' sets the default to verbose, which can be +overridden with `make V=0'. + +Particular systems +================== + + On HP-UX, the default C compiler is not ANSI C compatible. If GNU +CC is not installed, it is recommended to use the following options in +order to use an ANSI C compiler: + + ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" + +and if that doesn't work, install pre-built binaries of GCC for HP-UX. + + HP-UX `make' updates targets which have the same time stamps as +their prerequisites, which makes it generally unusable when shipped +generated files such as `configure' are involved. Use GNU `make' +instead. + + On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot +parse its `' header file. The option `-nodtk' can be used as +a workaround. If GNU CC is not installed, it is therefore recommended +to try + + ./configure CC="cc" + +and if that doesn't work, try + + ./configure CC="cc -nodtk" + + On Solaris, don't put `/usr/ucb' early in your `PATH'. This +directory contains several dysfunctional programs; working variants of +these programs are available in `/usr/bin'. So, if you need `/usr/ucb' +in your `PATH', put it _after_ `/usr/bin'. + + On Haiku, software installed for all users goes in `/boot/common', +not `/usr/local'. It is recommended to use the following options: + + ./configure --prefix=/boot/common + Specifying the System Type ========================== - There may be some features `configure' can not figure out -automatically, but needs to determine by the type of host the package -will run on. Usually `configure' can figure that out, but if it prints -a message saying it can not guess the host type, give it the -`--host=TYPE' option. TYPE can either be a short name for the system -type, such as `sun4', or a canonical name with three fields: + There may be some features `configure' cannot figure out +automatically, but needs to determine by the type of machine the package +will run on. Usually, assuming the package is built to be run on the +_same_ architectures, `configure' can figure that out, but if it prints +a message saying it cannot guess the machine type, give it the +`--build=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name which has the form: + CPU-COMPANY-SYSTEM -See the file `config.sub' for the possible values of each field. If -`config.sub' isn't included in this package, then this package doesn't -need to know the host type. +where SYSTEM can have one of these forms: - If you are building compiler tools for cross-compiling, you can also -use the `--target=TYPE' option to select the type of system they will -produce code for and the `--build=TYPE' option to select the type of -system on which you are compiling the package. + OS + KERNEL-OS + + See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the option `--target=TYPE' to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with `--host=TYPE'. Sharing Defaults ================ @@ -223,19 +294,56 @@ default values for variables like `CC', `cache_file', and `prefix'. `CONFIG_SITE' environment variable to the location of the site script. A warning: not all `configure' scripts look for a site script. -Operation Controls +Defining Variables ================== + Variables not defined in a site shell script can be set in the +environment passed to `configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the `configure' command line, using `VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +causes the specified `gcc' to be used as the C compiler (unless it is +overridden in the site shell script). + +Unfortunately, this technique does not work for `CONFIG_SHELL' due to +an Autoconf limitation. Until the limitation is lifted, you can use +this workaround: + + CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash + +`configure' Invocation +====================== + `configure' recognizes the following options to control how it operates. -`--cache-file=FILE' - Use and save the results of the tests in FILE instead of - `./config.cache'. Set FILE to `/dev/null' to disable caching, for - debugging `configure'. - `--help' - Print a summary of the options to `configure', and exit. +`-h' + Print a summary of all of the options to `configure', and exit. + +`--help=short' +`--help=recursive' + Print a summary of the options unique to this package's + `configure', and exit. The `short' variant lists options used + only in the top level, while the `recursive' variant lists options + also present in any nested packages. + +`--version' +`-V' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally `config.cache'. FILE defaults to `/dev/null' to + disable caching. + +`--config-cache' +`-C' + Alias for `--cache-file=config.cache'. `--quiet' `--silent' @@ -248,8 +356,15 @@ operates. Look for the package's source code in directory DIR. Usually `configure' can determine that directory automatically. -`--version' - Print the version of Autoconf used to generate the `configure' - script, and exit. +`--prefix=DIR' + Use DIR as the installation prefix. *note Installation Names:: + for more details, including other options available for fine-tuning + the installation locations. -`configure' also accepts some other, not widely useful, options. +`--no-create' +`-n' + Run the configure checks, but stop before creating any output + files. + +`configure' also accepts some other, not widely useful, options. Run +`configure --help' for more details. diff --git a/libs/spandsp/spandsp-sim/Makefile.am b/libs/spandsp/spandsp-sim/Makefile.am index d33575a55c..4eb86c4b49 100644 --- a/libs/spandsp/spandsp-sim/Makefile.am +++ b/libs/spandsp/spandsp-sim/Makefile.am @@ -34,7 +34,7 @@ EXTRA_DIST = libspandsp_sim.dsp \ msvc/vc9proj.head \ msvc/vc9proj.foot -INCLUDES = -I$(top_builddir) -I$(top_builddir)/src -DDATADIR="\"$(pkgdatadir)\"" +AM_CPPFLAGS = -I$(top_builddir) -I$(top_builddir)/src -DDATADIR="\"$(pkgdatadir)\"" noinst_PROGRAMS = make_line_models diff --git a/libs/spandsp/src/Makefile.am b/libs/spandsp/src/Makefile.am index a794e37fb5..7a28c27aad 100644 --- a/libs/spandsp/src/Makefile.am +++ b/libs/spandsp/src/Makefile.am @@ -78,7 +78,7 @@ EXTRA_DIST = floating_fudge.h \ spandsp/private/README \ spandsp/version.h.in -INCLUDES = -I$(top_builddir) +AM_CPPFLAGS = -I$(top_builddir) lib_LTLIBRARIES = libspandsp.la diff --git a/libs/spandsp/src/spandsp/t4_tx.h b/libs/spandsp/src/spandsp/t4_tx.h index b411892c78..41974c9fcf 100644 --- a/libs/spandsp/src/spandsp/t4_tx.h +++ b/libs/spandsp/src/spandsp/t4_tx.h @@ -323,12 +323,6 @@ SPAN_DECLARE(int) t4_tx_set_tx_image_format(t4_tx_state_t *s, int supported_bilevel_resolutions, int supported_colour_resolutions); -/*! \brief Set the compression for the encoded data. - \param s The T.4 context. - \param encoding The encoding. - \return 0 for success, otherwise -1. */ -SPAN_DECLARE(int) t4_tx_set_tx_encoding(t4_tx_state_t *s, int encoding); - /*! \brief Set the minimum number of encoded bits per row. This allows the makes the encoding process to be set to comply with the minimum row time specified by a remote receiving machine. @@ -336,11 +330,6 @@ SPAN_DECLARE(int) t4_tx_set_tx_encoding(t4_tx_state_t *s, int encoding); \param bits The minimum number of bits per row. */ SPAN_DECLARE(void) t4_tx_set_min_bits_per_row(t4_tx_state_t *s, int bits); -/*! \brief Set the width of the image. - \param s The T.4 context. - \param image_width The image width, in pixels. */ -SPAN_DECLARE(void) t4_tx_set_image_width(t4_tx_state_t *s, int image_width); - /*! \brief Set the maximum number of 2D encoded rows between 1D encoded rows. This is only valid for T.4 2D encoding. \param s The T.4 context. @@ -381,12 +370,6 @@ SPAN_DECLARE(void) t4_tx_set_header_overlays_image(t4_tx_state_t *s, int header_ \return 0 for success, otherwise -1. */ SPAN_DECLARE(int) t4_tx_set_row_read_handler(t4_tx_state_t *s, t4_row_read_handler_t handler, void *user_data); -/*! \brief Set the row squashing ratio, for adjusting row-to-row (y) resolution of bi-level - images for a T.4 transmit context. - \param s The T.4 transmit context. - \param row_squashing_ratio Vertical squashing ratio. */ -SPAN_DECLARE(void) t4_tx_set_row_squashing_ratio(t4_tx_state_t *s, int row_squashing_ratio); - /*! \brief Get the number of pages in the file. \param s The T.4 context. \return The number of pages, or -1 if there is an error. */ diff --git a/libs/spandsp/src/t30.c b/libs/spandsp/src/t30.c index 484b627a2b..3a4a12acf5 100644 --- a/libs/spandsp/src/t30.c +++ b/libs/spandsp/src/t30.c @@ -1224,7 +1224,7 @@ int t30_build_dis_or_dtc(t30_state_t *s) // set_ctrl_bit(s->local_dis_dtc_frame, T30_DIS_BIT_T88_CAPABILITY_3); //} - //if ((s->supported_compressions & (T4_COMPRESSION_COLOUR | T4_COMPRESSION_GRAYSCALE))) + if ((s->supported_compressions & (T4_COMPRESSION_COLOUR | T4_COMPRESSION_GRAYSCALE))) { if ((s->supported_compressions & T4_COMPRESSION_COLOUR)) set_ctrl_bit(s->local_dis_dtc_frame, T30_DIS_BIT_FULL_COLOUR_CAPABLE); @@ -1249,8 +1249,8 @@ int t30_build_dis_or_dtc(t30_state_t *s) if ((s->supported_compressions & T4_COMPRESSION_12BIT)) set_ctrl_bit(s->local_dis_dtc_frame, T30_DIS_BIT_12BIT_CAPABLE); - //if ((s->supported_compressions & T4_COMPRESSION_NO_SUBSAMPLING)) - // set_ctrl_bit(s->local_dis_dtc_frame, T30_DIS_BIT_NO_SUBSAMPLING); + if ((s->supported_compressions & T4_COMPRESSION_NO_SUBSAMPLING)) + set_ctrl_bit(s->local_dis_dtc_frame, T30_DIS_BIT_NO_SUBSAMPLING); /* No custom illuminant */ /* No custom gamut range */ @@ -1423,8 +1423,6 @@ static int prune_dis_dtc(t30_state_t *s) static int build_dcs(t30_state_t *s) { int i; - int bad; - int row_squashing_ratio; int use_bilevel; int image_type; @@ -1523,229 +1521,21 @@ static int build_dcs(t30_state_t *s) break; } - /* Set the Y resolution bits */ - row_squashing_ratio = 1; - bad = T30_ERR_NORESSUPPORT; - if ((use_bilevel && (s->current_page_resolution & s->mutual_bilevel_resolutions)) - || - (!use_bilevel && (s->current_page_resolution & s->mutual_colour_resolutions))) - { - /* The resolution is supported by both parties */ - switch (s->current_page_resolution) - { - case T4_RESOLUTION_1200_1200: - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_1200_1200); - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); - if (!use_bilevel) - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_COLOUR_GRAY_1200_1200); - break; - case T4_RESOLUTION_600_1200: - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_600_1200); - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); - break; - case T4_RESOLUTION_600_600: - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_600_600); - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); - if (!use_bilevel) - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_COLOUR_GRAY_600_600); - break; - case T4_RESOLUTION_400_800: - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_400_800); - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); - break; - case T4_RESOLUTION_400_400: - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_400_400); - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); - if (!use_bilevel) - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_COLOUR_GRAY_300_300_400_400); - break; - case T4_RESOLUTION_300_600: - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_300_600); - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); - break; - case T4_RESOLUTION_300_300: - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_300_300); - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); - if (!use_bilevel) - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_COLOUR_GRAY_300_300_400_400); - break; - case T4_RESOLUTION_200_400: - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_200_400); - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); - break; - case T4_RESOLUTION_200_200: - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_200_200); - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); - if (!use_bilevel) - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_FULL_COLOUR_MODE); - break; - case T4_RESOLUTION_200_100: - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); - break; - case T4_RESOLUTION_100_100: - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); - if (!use_bilevel) - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_COLOUR_GRAY_100_100); - break; - case T4_RESOLUTION_R16_SUPERFINE: - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_400_400); - break; - case T4_RESOLUTION_R8_SUPERFINE: - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_200_400); - break; - case T4_RESOLUTION_R8_FINE: - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_200_200); - break; - case T4_RESOLUTION_R8_STANDARD: - /* Nothing special to set */ - break; - } - bad = T30_ERR_OK; - } - else - { -#if 0 - /* Deal with resolution fudging */ - if ((s->current_page_resolution & (T4_RESOLUTION_R16_SUPERFINE | T4_RESOLUTION_R8_SUPERFINE | T4_RESOLUTION_R8_FINE | T4_RESOLUTION_R8_STANDARD))) - { - if ((s->mutual_bilevel_resolutions & (T4_RESOLUTION_400_400 | T4_RESOLUTION_200_400 | T4_RESOLUTION_200_200 | T4_RESOLUTION_200_100))) - { - /* Fudge between imperial and metric */ - } - } - else if ((s->current_page_resolution & (T4_RESOLUTION_400_400 | T4_RESOLUTION_200_400 | T4_RESOLUTION_200_200 | T4_RESOLUTION_200_100)) - { - if ((s->mutual_bilevel_resolutions & (T4_RESOLUTION_R16_SUPERFINE | T4_RESOLUTION_R8_SUPERFINE | T4_RESOLUTION_R8_FINE | T4_RESOLUTION_R8_STANDARD))) - { - /* Fudge between imperial and metric */ - } - } -#endif - /* Deal with squashing options */ - if ((s->current_page_resolution & T4_RESOLUTION_R8_SUPERFINE)) - { - if ((s->mutual_bilevel_resolutions & T4_RESOLUTION_R8_FINE)) - { - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_200_200); - row_squashing_ratio = 2; - bad = T30_ERR_OK; - } - else if ((s->mutual_bilevel_resolutions & T4_RESOLUTION_R8_STANDARD)) - { - row_squashing_ratio = 4; - bad = T30_ERR_OK; - } - } - else if ((s->current_page_resolution & T4_RESOLUTION_R8_FINE) && (s->mutual_bilevel_resolutions & T4_RESOLUTION_R8_STANDARD)) - { - row_squashing_ratio = 2; - bad = T30_ERR_OK; - } - else if ((s->current_page_resolution & T4_RESOLUTION_200_400)) - { - if ((s->mutual_bilevel_resolutions & T4_RESOLUTION_200_200)) - { - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_200_200); - row_squashing_ratio = 2; - bad = T30_ERR_OK; - } - else if ((s->mutual_bilevel_resolutions & T4_RESOLUTION_200_100)) - { - row_squashing_ratio = 4; - bad = T30_ERR_OK; - } - } - else if ((s->current_page_resolution & T4_RESOLUTION_200_200) && (s->mutual_bilevel_resolutions & T4_RESOLUTION_200_100)) - { - row_squashing_ratio = 2; - bad = T30_ERR_OK; - } - } - - t4_tx_set_row_squashing_ratio(&s->t4.tx, row_squashing_ratio); - if (bad != T30_ERR_OK) - { - t30_set_status(s, bad); - span_log(&s->logging, SPAN_LOG_FLOW, "Image resolution (%d x %d) not acceptable\n", s->x_resolution, s->y_resolution); - return -1; - } - - /* Deal with the image width. */ - /* Low (R4) res widths are not supported in recent versions of T.30 */ - bad = T30_ERR_OK; - /* The following treats a width field of 11 like 10, which does what note 6 of Table 2/T.30 - says we should do with the invalid value 11. */ - if (((s->image_width == T4_WIDTH_200_A4) && (s->x_resolution == T4_X_RESOLUTION_200 || s->x_resolution == T4_X_RESOLUTION_R8)) - || - ((s->image_width == T4_WIDTH_300_A4) && (s->x_resolution == T4_X_RESOLUTION_300)) - || - ((s->image_width == T4_WIDTH_400_A4) && (s->x_resolution == T4_X_RESOLUTION_400 || s->x_resolution == T4_X_RESOLUTION_R16)) - || - ((s->image_width == T4_WIDTH_600_A4) && (s->x_resolution == T4_X_RESOLUTION_600)) - || - ((s->image_width == T4_WIDTH_1200_A4) && (s->x_resolution == T4_X_RESOLUTION_1200))) + /* Set the image width */ + switch (s->line_width_code) { + case T4_SUPPORT_WIDTH_215MM: span_log(&s->logging, SPAN_LOG_FLOW, "Image width is A4 at %ddpm x %ddpm\n", s->x_resolution, s->y_resolution); /* No width related bits need to be set. */ - } - else if (((s->image_width == T4_WIDTH_200_B4) && (s->x_resolution == T4_X_RESOLUTION_200 || s->x_resolution == T4_X_RESOLUTION_R8)) - || - ((s->image_width == T4_WIDTH_300_B4) && (s->x_resolution == T4_X_RESOLUTION_300)) - || - ((s->image_width == T4_WIDTH_400_B4) && (s->x_resolution == T4_X_RESOLUTION_400 || s->x_resolution == T4_X_RESOLUTION_R16)) - || - ((s->image_width == T4_WIDTH_600_B4) && (s->x_resolution == T4_X_RESOLUTION_600)) - || - ((s->image_width == T4_WIDTH_1200_B4) && (s->x_resolution == T4_X_RESOLUTION_1200))) - { - if ((s->mutual_image_sizes & T4_SUPPORT_WIDTH_255MM)) - { - span_log(&s->logging, SPAN_LOG_FLOW, "Image width is B4 at %ddpm x %ddpm\n", s->x_resolution, s->y_resolution); - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_255MM_WIDTH); - } - else - { - /* We do not support this width and resolution combination */ - bad = T30_ERR_NOSIZESUPPORT; - } - } - else if (((s->image_width == T4_WIDTH_200_A3) && (s->x_resolution == T4_X_RESOLUTION_200 || s->x_resolution == T4_X_RESOLUTION_R8)) - || - ((s->image_width == T4_WIDTH_300_A3) && (s->x_resolution == T4_X_RESOLUTION_300)) - || - ((s->image_width == T4_WIDTH_400_A3) && (s->x_resolution == T4_X_RESOLUTION_400 || s->x_resolution == T4_X_RESOLUTION_R16)) - || - ((s->image_width == T4_WIDTH_600_A3) && (s->x_resolution == T4_X_RESOLUTION_600)) - || - ((s->image_width == T4_WIDTH_1200_A3) && (s->x_resolution == T4_X_RESOLUTION_1200))) - { - if ((s->mutual_image_sizes & T4_SUPPORT_WIDTH_303MM)) - { - span_log(&s->logging, SPAN_LOG_FLOW, "Image width is A3 at %ddpm x %ddpm\n", s->x_resolution, s->y_resolution); - set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_303MM_WIDTH); - } - else - { - /* We do not support this width and resolution combination */ - bad = T30_ERR_NOSIZESUPPORT; - } - } - else - { - /* We do not support this width and resolution combination */ - bad = T30_ERR_NOSIZESUPPORT; - } - - if (bad != T30_ERR_OK) - { - t30_set_status(s, bad); - span_log(&s->logging, - SPAN_LOG_FLOW, - "Image width (%d pixels) and resolution (%d x %d) is not an acceptable\n", - s->image_width, - s->x_resolution, - s->y_resolution); - return -1; + break; + case T4_SUPPORT_WIDTH_255MM: + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_255MM_WIDTH); + span_log(&s->logging, SPAN_LOG_FLOW, "Image width is B4 at %ddpm x %ddpm\n", s->x_resolution, s->y_resolution); + break; + case T4_SUPPORT_WIDTH_303MM: + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_303MM_WIDTH); + span_log(&s->logging, SPAN_LOG_FLOW, "Image width is A3 at %ddpm x %ddpm\n", s->x_resolution, s->y_resolution); + break; } /* Set the image length */ @@ -1760,6 +1550,77 @@ static int build_dcs(t30_state_t *s) else if ((s->mutual_image_sizes & T4_SUPPORT_LENGTH_US_LEGAL)) set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_NORTH_AMERICAN_LEGAL); + /* Set the Y resolution bits */ + switch (s->current_page_resolution) + { + case T4_RESOLUTION_1200_1200: + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_1200_1200); + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); + if (!use_bilevel) + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_COLOUR_GRAY_1200_1200); + break; + case T4_RESOLUTION_600_1200: + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_600_1200); + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); + break; + case T4_RESOLUTION_600_600: + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_600_600); + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); + if (!use_bilevel) + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_COLOUR_GRAY_600_600); + break; + case T4_RESOLUTION_400_800: + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_400_800); + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); + break; + case T4_RESOLUTION_400_400: + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_400_400); + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); + if (!use_bilevel) + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_COLOUR_GRAY_300_300_400_400); + break; + case T4_RESOLUTION_300_600: + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_300_600); + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); + break; + case T4_RESOLUTION_300_300: + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_300_300); + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); + if (!use_bilevel) + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_COLOUR_GRAY_300_300_400_400); + break; + case T4_RESOLUTION_200_400: + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_200_400); + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); + break; + case T4_RESOLUTION_200_200: + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_200_200); + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); + if (!use_bilevel) + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_FULL_COLOUR_MODE); + break; + case T4_RESOLUTION_200_100: + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); + break; + case T4_RESOLUTION_100_100: + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_INCH_RESOLUTION); + if (!use_bilevel) + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_COLOUR_GRAY_100_100); + break; + case T4_RESOLUTION_R16_SUPERFINE: + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_400_400); + break; + case T4_RESOLUTION_R8_SUPERFINE: + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_200_400); + break; + case T4_RESOLUTION_R8_FINE: + set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_200_200); + break; + case T4_RESOLUTION_R8_STANDARD: + /* Nothing special to set */ + break; + } + if (s->error_correcting_mode) set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_ECM_MODE); @@ -1832,7 +1693,7 @@ static int analyze_rx_dis_dtc(t30_state_t *s, const uint8_t *msg, int len) if (!s->error_correcting_mode) { /* Remove any compression schemes which need error correction to work. */ - s->mutual_compressions &= (0xF0000000 | T4_COMPRESSION_NONE | T4_COMPRESSION_T4_1D | T4_COMPRESSION_T4_2D); + s->mutual_compressions &= (0xFF800000 | T4_COMPRESSION_NONE | T4_COMPRESSION_T4_1D | T4_COMPRESSION_T4_2D); if (!test_ctrl_bit(s->far_dis_dtc_frame, T30_DIS_BIT_2D_CAPABLE)) s->mutual_compressions &= ~T4_COMPRESSION_T4_2D; } @@ -1866,8 +1727,8 @@ static int analyze_rx_dis_dtc(t30_state_t *s, const uint8_t *msg, int len) if (!test_ctrl_bit(s->far_dis_dtc_frame, T30_DIS_BIT_12BIT_CAPABLE)) s->mutual_compressions &= ~T4_COMPRESSION_12BIT; - //if (!test_ctrl_bit(s->far_dis_dtc_frame, T30_DIS_BIT_NO_SUBSAMPLING)) - // ???? = T4_COMPRESSION_T42_T81_SUBSAMPLING; + if (!test_ctrl_bit(s->far_dis_dtc_frame, T30_DIS_BIT_NO_SUBSAMPLING)) + s->mutual_compressions &= ~T4_COMPRESSION_NO_SUBSAMPLING; /* bit74 custom illuminant */ /* bit75 custom gamut range */ @@ -2087,7 +1948,7 @@ static int analyze_rx_dcs(t30_state_t *s, const uint8_t *msg, int len) if (test_ctrl_bit(dcs_frame, T30_DCS_BIT_NO_SUBSAMPLING)) { - //???? = T4_COMPRESSION_T42_T81_SUBSAMPLING; + //???? = T4_COMPRESSION_NO_SUBSAMPLING; } if (!test_ctrl_bit(dcs_frame, T30_DCS_BIT_PREFERRED_HUFFMAN_TABLES)) @@ -2529,7 +2390,6 @@ static int send_dcs_sequence(t30_state_t *s, int start) /* Schedule training after the messages */ if (start) { - prune_dcs(s); set_state(s, T30_STATE_D); s->step = 0; } @@ -2654,22 +2514,12 @@ static void set_min_scan_time(t30_state_t *s) { case T4_Y_RESOLUTION_SUPERFINE: case T4_Y_RESOLUTION_400: - if (test_ctrl_bit(s->far_dis_dtc_frame, T30_DIS_BIT_200_400_CAPABLE)) - { - s->min_scan_time_code = translate_min_scan_time[(test_ctrl_bit(s->far_dis_dtc_frame, T30_DIS_BIT_MIN_SCAN_TIME_HALVES)) ? 2 : 1][min_bits_field]; - break; - } - span_log(&s->logging, SPAN_LOG_FLOW, "Remote FAX does not support super-fine resolution. Squashing image.\n"); - /* Fall through */ + s->min_scan_time_code = translate_min_scan_time[(test_ctrl_bit(s->far_dis_dtc_frame, T30_DIS_BIT_MIN_SCAN_TIME_HALVES)) ? 2 : 1][min_bits_field]; + break; case T4_Y_RESOLUTION_FINE: case T4_Y_RESOLUTION_200: - if (test_ctrl_bit(s->far_dis_dtc_frame, T30_DIS_BIT_200_200_CAPABLE)) - { - s->min_scan_time_code = translate_min_scan_time[1][min_bits_field]; - break; - } - span_log(&s->logging, SPAN_LOG_FLOW, "Remote FAX does not support fine resolution. Squashing image.\n"); - /* Fall through */ + s->min_scan_time_code = translate_min_scan_time[1][min_bits_field]; + break; case T4_Y_RESOLUTION_STANDARD: case T4_Y_RESOLUTION_100: s->min_scan_time_code = translate_min_scan_time[0][min_bits_field]; @@ -2689,6 +2539,8 @@ static void set_min_scan_time(t30_state_t *s) static int start_sending_document(t30_state_t *s) { + int res; + if (s->tx_file[0] == '\0') { /* There is nothing to send */ @@ -2703,27 +2555,68 @@ static int start_sending_document(t30_state_t *s) return -1; } s->operation_in_progress = OPERATION_IN_PROGRESS_T4_TX; - t4_tx_get_pages_in_file(&s->t4.tx); - t4_tx_set_tx_encoding(&s->t4.tx, s->line_compression); + t4_tx_set_local_ident(&s->t4.tx, s->tx_info.ident); t4_tx_set_header_info(&s->t4.tx, s->header_info); if (s->use_own_tz) t4_tx_set_header_tz(&s->t4.tx, &s->tz); - if (tx_start_page(s)) + t4_tx_get_pages_in_file(&s->t4.tx); + + if ((res = t4_tx_set_tx_image_format(&s->t4.tx, + s->mutual_compressions, + s->mutual_image_sizes, + s->mutual_bilevel_resolutions, + s->mutual_colour_resolutions)) < 0) { - span_log(&s->logging, SPAN_LOG_WARNING, "Something seems to be wrong in the file\n"); - t30_set_status(s, T30_ERR_FILEERROR); + switch (res) + { + case T4_IMAGE_FORMAT_INCOMPATIBLE: + span_log(&s->logging, SPAN_LOG_WARNING, "Cannot negotiate an image format\n"); + t30_set_status(s, T30_ERR_BADTIFFHDR); + break; + case T4_IMAGE_FORMAT_NOSIZESUPPORT: + span_log(&s->logging, SPAN_LOG_WARNING, "Cannot negotiate an image size\n"); + t30_set_status(s, T30_ERR_NOSIZESUPPORT); + break; + case T4_IMAGE_FORMAT_NORESSUPPORT: + span_log(&s->logging, SPAN_LOG_WARNING, "Cannot negotiate an image resolution\n"); + t30_set_status(s, T30_ERR_NORESSUPPORT); + break; + default: + span_log(&s->logging, SPAN_LOG_WARNING, "Cannot negotiate an image format\n"); + t30_set_status(s, T30_ERR_BADTIFF); + break; + } return -1; } + s->line_image_type = t4_tx_get_tx_image_type(&s->t4.tx); + s->line_compression = t4_tx_get_tx_compression(&s->t4.tx); + s->image_width = t4_tx_get_tx_image_width(&s->t4.tx); + s->line_width_code = t4_tx_get_tx_image_width_code(&s->t4.tx); s->x_resolution = t4_tx_get_tx_x_resolution(&s->t4.tx); s->y_resolution = t4_tx_get_tx_y_resolution(&s->t4.tx); - s->image_width = t4_tx_get_tx_image_width(&s->t4.tx); - /* The minimum scan time to be used can't be evaluated until we know the Y resolution, and - must be evaluated before the minimum scan row bits can be evaluated. */ + s->current_page_resolution = t4_tx_get_tx_resolution(&s->t4.tx); + + span_log(&s->logging, + SPAN_LOG_FLOW, + "Choose image type %s (%d), compression %s (%d)\n", + t4_image_type_to_str(s->line_image_type), + s->line_image_type, + t4_compression_to_str(s->line_compression), + s->line_compression); + + /* The minimum scan time to be used can't be evaluated until we know the Y resolution. */ set_min_scan_time(s); + if (tx_start_page(s)) + { + span_log(&s->logging, SPAN_LOG_WARNING, "Something seems to be wrong in the file\n"); + t30_set_status(s, T30_ERR_BADTIFFHDR); + return -1; + } + if (s->error_correcting_mode) { if (get_partial_ecm_page(s) == 0) @@ -2795,21 +2688,6 @@ static int process_rx_dis_dtc(t30_state_t *s, const uint8_t *msg, int len) send_dcn(s); return -1; } - - /* Choose a compression scheme from amongst those mutually available */ - if ((s->mutual_compressions & T4_COMPRESSION_T85_L0)) - s->line_compression = T4_COMPRESSION_T85_L0; - else if ((s->mutual_compressions & T4_COMPRESSION_T85)) - s->line_compression = T4_COMPRESSION_T85; - else if ((s->mutual_compressions & T4_COMPRESSION_T6)) - s->line_compression = T4_COMPRESSION_T6; - else if ((s->mutual_compressions & T4_COMPRESSION_T4_2D)) - s->line_compression = T4_COMPRESSION_T4_2D; - else - s->line_compression = T4_COMPRESSION_T4_1D; - - span_log(&s->logging, SPAN_LOG_FLOW, "Choose compression %s (%d)\n", t4_compression_to_str(s->line_compression), s->line_compression); - if (s->phase_b_handler) { new_status = s->phase_b_handler(s, s->phase_b_user_data, msg[2]); @@ -6825,7 +6703,7 @@ SPAN_DECLARE(t30_state_t *) t30_init(t30_state_t *s, | T4_SUPPORT_LENGTH_UNLIMITED; /* Set the output encoding to something safe. Most things get 1D and 2D encoding right. Quite a lot get other things wrong. */ - s->supported_output_compressions = T4_COMPRESSION_T4_2D; + s->supported_output_compressions = T4_COMPRESSION_T4_2D | T4_COMPRESSION_T42_T81; s->local_min_scan_time_code = T30_MIN_SCAN_0MS; span_log_init(&s->logging, SPAN_LOG_NONE, NULL); span_log_set_protocol(&s->logging, "T.30"); diff --git a/libs/spandsp/src/t4_rx.c b/libs/spandsp/src/t4_rx.c index 5a7bb6bc45..b7bed5dd18 100644 --- a/libs/spandsp/src/t4_rx.c +++ b/libs/spandsp/src/t4_rx.c @@ -234,11 +234,24 @@ static int set_tiff_directory_info(t4_rx_state_t *s) #endif #if defined(SPANDSP_SUPPORT_T42) case T4_COMPRESSION_T42_T81: + output_compression = COMPRESSION_JPEG; + bits_per_sample = 8; + if (t->image_type == T4_IMAGE_TYPE_COLOUR_8BIT) + { + samples_per_pixel = 3; + photometric = PHOTOMETRIC_YCBCR; //PHOTOMETRIC_ITULAB; + } + else + { + samples_per_pixel = 1; + photometric = PHOTOMETRIC_MINISBLACK; + } + break; case T4_COMPRESSION_SYCC_T81: output_compression = COMPRESSION_JPEG; bits_per_sample = 8; samples_per_pixel = 3; - photometric = PHOTOMETRIC_ITULAB; + photometric = PHOTOMETRIC_YCBCR; break; #endif #if defined(SPANDSP_SUPPORT_T43) @@ -288,6 +301,13 @@ static int set_tiff_directory_info(t4_rx_state_t *s) TIFFSetField(t->tiff_file, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); TIFFSetField(t->tiff_file, TIFFTAG_PHOTOMETRIC, photometric); TIFFSetField(t->tiff_file, TIFFTAG_FILLORDER, FILLORDER_LSB2MSB); + if (t->compression == T4_COMPRESSION_T42_T81) + { + TIFFSetField(t->tiff_file, TIFFTAG_YCBCRSUBSAMPLING, 2, 2); + //TIFFSetField(t->tiff_file, TIFFTAG_YCBCRSUBSAMPLING, 1, 1); + TIFFSetField(t->tiff_file, TIFFTAG_JPEGQUALITY, 75); + TIFFSetField(t->tiff_file, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB); + } /* TIFFTAG_STRIPBYTECOUNTS and TIFFTAG_STRIPOFFSETS are added automatically */ x_resolution = s->metadata.x_resolution/100.0f; @@ -344,30 +364,32 @@ static int set_tiff_directory_info(t4_rx_state_t *s) is always one greater than the highest page number in the file. */ s->tiff.pages_in_file = s->current_page + 1; s->metadata.image_length = 0; - switch (s->metadata.compression) + switch (s->current_decoder) { - case T4_COMPRESSION_T4_1D: - case T4_COMPRESSION_T4_2D: - /* We only get bad row info from pages received in non-ECM mode. */ - if (output_compression == COMPRESSION_CCITT_T4) + case 0: + s->metadata.image_length = 1024; + break; + case T4_COMPRESSION_T4_1D | T4_COMPRESSION_T4_2D | T4_COMPRESSION_T6: + if ((s->metadata.compression & (T4_COMPRESSION_T4_1D | T4_COMPRESSION_T4_2D))) { - if (s->decoder.t4_t6.bad_rows) + /* We only get bad row info from pages received in non-ECM mode. */ + if (output_compression == COMPRESSION_CCITT_T4) { - TIFFSetField(t->tiff_file, TIFFTAG_BADFAXLINES, s->decoder.t4_t6.bad_rows); - TIFFSetField(t->tiff_file, TIFFTAG_CONSECUTIVEBADFAXLINES, s->decoder.t4_t6.longest_bad_row_run); - TIFFSetField(t->tiff_file, TIFFTAG_CLEANFAXDATA, CLEANFAXDATA_REGENERATED); - } - else - { - TIFFSetField(t->tiff_file, TIFFTAG_CLEANFAXDATA, CLEANFAXDATA_CLEAN); + if (s->decoder.t4_t6.bad_rows) + { + TIFFSetField(t->tiff_file, TIFFTAG_BADFAXLINES, s->decoder.t4_t6.bad_rows); + TIFFSetField(t->tiff_file, TIFFTAG_CONSECUTIVEBADFAXLINES, s->decoder.t4_t6.longest_bad_row_run); + TIFFSetField(t->tiff_file, TIFFTAG_CLEANFAXDATA, CLEANFAXDATA_REGENERATED); + } + else + { + TIFFSetField(t->tiff_file, TIFFTAG_CLEANFAXDATA, CLEANFAXDATA_CLEAN); + } } } - /* Fall through */ - case T4_COMPRESSION_T6: s->metadata.image_length = t4_t6_decode_get_image_length(&s->decoder.t4_t6); break; - case T4_COMPRESSION_T85: - case T4_COMPRESSION_T85_L0: + case T4_COMPRESSION_T85 | T4_COMPRESSION_T85_L0: s->metadata.image_length = t85_decode_get_image_length(&s->decoder.t85); break; #if defined(SPANDSP_SUPPORT_T88) @@ -401,6 +423,34 @@ static int set_tiff_directory_info(t4_rx_state_t *s) /* Create a placeholder for the global parameters IFD, to be filled in later */ TIFFSetField(t->tiff_file, TIFFTAG_GLOBALPARAMETERSIFD, 0); } + +#if 0 + /* Paletised image? */ + TIFFSetField(t->tiff_file, TIFFTAG_INDEXED, 1); + /* T.44 mode */ + TIFFSetField(t->tiff_file, TIFFTAG_MODENUMBER, 0); + span_log(&s->logging, SPAN_LOG_FLOW, "TIFF/FX stuff 2\n"); + { + float xxx[] = {20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0}; + TIFFSetField(t->tiff_file, TIFFTAG_DECODE, (uint16) 2*samples_per_pixel, xxx); + } + span_log(&s->logging, SPAN_LOG_FLOW, "TIFF/FX stuff 3\n"); + { + uint16_t xxx[] = {12, 34, 45, 67}; + TIFFSetField(t->tiff_file, TIFFTAG_IMAGEBASECOLOR, (uint16_t) samples_per_pixel, xxx); + } + span_log(&s->logging, SPAN_LOG_FLOW, "TIFF/FX stuff 4\n"); + TIFFSetField(t->tiff_file, TIFFTAG_T82OPTIONS, 0); + { + uint32_t xxx[] = {34, 56, 78, 90}; + TIFFSetField(t->tiff_file, TIFFTAG_STRIPROWCOUNTS, (uint16_t) 5, xxx); + } + span_log(&s->logging, SPAN_LOG_FLOW, "TIFF/FX stuff 5\n"); + { + uint32_t xxx[] = {2, 3}; + TIFFSetField(t->tiff_file, TIFFTAG_IMAGELAYER, xxx); + } +#endif #endif return 0; } @@ -450,10 +500,10 @@ static int write_tiff_t85_image(t4_rx_state_t *s) if (buf_len < image_len + 65536) { buf_len += 65536; - if ((buf2 = realloc(buf, buf_len)) == NULL) + if ((buf2 = span_realloc(buf, buf_len)) == NULL) { if (buf) - free(buf); + span_free(buf); return -1; } buf = buf2; @@ -468,7 +518,7 @@ static int write_tiff_t85_image(t4_rx_state_t *s) return -1; } t85_encode_release(&t85); - free(buf); + span_free(buf); return 0; } /*- End of function --------------------------------------------------------*/ @@ -496,10 +546,10 @@ static int write_tiff_t43_image(t4_rx_state_t *s) if (buf_len < image_len + 65536) { buf_len += 65536; - if ((buf2 = realloc(buf, buf_len)) == NULL) + if ((buf2 = span_realloc(buf, buf_len)) == NULL) { if (buf) - free(buf); + span_free(buf); return -1; } buf = buf2; @@ -511,7 +561,7 @@ static int write_tiff_t43_image(t4_rx_state_t *s) if (TIFFWriteRawStrip(s->tiff.tiff_file, 0, buf, image_len) < 0) span_log(&s->logging, SPAN_LOG_WARNING, "%s: Error writing TIFF strip.\n", s->tiff.file); t43_encode_release(&t43); - free(buf); + span_free(buf); return 0; } /*- End of function --------------------------------------------------------*/ @@ -525,49 +575,57 @@ static int write_tiff_image(t4_rx_state_t *s) #endif t = &s->tiff; - if (t->image_buffer == NULL || t->image_size <= 0) + if (s->pre_encoded_ptr <= 0 && (t->image_buffer == NULL || t->image_size <= 0)) return -1; /* Set up the TIFF directory info... */ set_tiff_directory_info(s); /* ...Put the directory in the file before the image data, to get them in the order specified for TIFF/F files... */ - if (!TIFFCheckpointDirectory(t->tiff_file)) - span_log(&s->logging, SPAN_LOG_WARNING, "%s: Failed to checkpoint directory for page %d.\n", t->file, s->current_page); + //if (!TIFFCheckpointDirectory(t->tiff_file)) + // span_log(&s->logging, SPAN_LOG_WARNING, "%s: Failed to checkpoint directory for page %d.\n", t->file, s->current_page); /* ...and write out the image... */ - switch (t->compression) + if (s->pre_encoded_ptr > 0) { - case T4_COMPRESSION_T85: - case T4_COMPRESSION_T85_L0: - /* We need to perform this compression here, as libtiff does not understand it. */ - if (write_tiff_t85_image(s) < 0) - return -1; - break; + if (TIFFWriteRawStrip(s->tiff.tiff_file, 0, s->pre_encoded_buf, s->pre_encoded_ptr) < 0) + span_log(&s->logging, SPAN_LOG_WARNING, "%s: Error writing TIFF strip.\n", s->tiff.file); + } + else + { + switch (t->compression) + { + case T4_COMPRESSION_T85: + case T4_COMPRESSION_T85_L0: + /* We need to perform this compression here, as libtiff does not understand it. */ + if (write_tiff_t85_image(s) < 0) + return -1; + break; #if defined(SPANDSP_SUPPORT_T88) - case T4_COMPRESSION_T88: - /* We need to perform this compression here, as libtiff does not understand it. */ - if (write_tiff_t88_image(s) < 0) - return -1; - break; + case T4_COMPRESSION_T88: + /* We need to perform this compression here, as libtiff does not understand it. */ + if (write_tiff_t88_image(s) < 0) + return -1; + break; #endif #if defined(SPANDSP_SUPPORT_T43) - case T4_COMPRESSION_T43: - /* We need to perform this compression here, as libtiff does not understand it. */ - if (write_tiff_t43_image(s) < 0) - return -1; - break; + case T4_COMPRESSION_T43: + /* We need to perform this compression here, as libtiff does not understand it. */ + if (write_tiff_t43_image(s) < 0) + return -1; + break; #endif #if defined(SPANDSP_SUPPORT_T45) - case T4_COMPRESSION_T45: - /* We need to perform this compression here, as libtiff does not understand it. */ - if (write_tiff_t45_image(s) < 0) - return -1; - break; + case T4_COMPRESSION_T45: + /* We need to perform this compression here, as libtiff does not understand it. */ + if (write_tiff_t45_image(s) < 0) + return -1; + break; #endif - default: - /* Let libtiff do the compression */ - if (TIFFWriteEncodedStrip(t->tiff_file, 0, t->image_buffer, t->image_size) < 0) - span_log(&s->logging, SPAN_LOG_WARNING, "%s: Error writing TIFF strip.\n", t->file); - break; + default: + /* Let libtiff do the compression */ + if (TIFFWriteEncodedStrip(t->tiff_file, 0, t->image_buffer, t->image_size) < 0) + span_log(&s->logging, SPAN_LOG_WARNING, "%s: Error writing TIFF strip.\n", t->file); + break; + } } /* ...then finalise the directory entry, and libtiff is happy. */ if (!TIFFWriteDirectory(t->tiff_file)) @@ -633,7 +691,7 @@ static int close_tiff_output_file(t4_rx_state_t *s) put in it. */ if (s->current_page == 0) remove(s->tiff.file); - free((char *) s->tiff.file); + span_free((char *) s->tiff.file); } s->tiff.file = NULL; return 0; @@ -646,7 +704,7 @@ static void tiff_rx_release(t4_rx_state_t *s) close_tiff_output_file(s); if (s->tiff.image_buffer) { - free(s->tiff.image_buffer); + span_free(s->tiff.image_buffer); s->tiff.image_buffer = NULL; s->tiff.image_size = 0; s->tiff.image_buffer_size = 0; @@ -673,10 +731,10 @@ SPAN_DECLARE(int) t4_rx_put(t4_rx_state_t *s, const uint8_t buf[], size_t len) if (s->pre_encoded_len < s->pre_encoded_ptr + 65536) { s->pre_encoded_len += 65536; - if ((buf2 = realloc(s->pre_encoded_buf, s->pre_encoded_len)) == NULL) + if ((buf2 = span_realloc(s->pre_encoded_buf, s->pre_encoded_len)) == NULL) { if (s->pre_encoded_buf) - free(s->pre_encoded_buf); + span_free(s->pre_encoded_buf); return -1; } s->pre_encoded_buf = buf2; @@ -757,11 +815,19 @@ static void select_tiff_compression(t4_rx_state_t *s, int output_image_type) else if ((s->supported_tiff_compressions & T4_COMPRESSION_T43)) s->tiff.compression = T4_COMPRESSION_T43; } + s->tiff.image_type = output_image_type; } /*- End of function --------------------------------------------------------*/ SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int compression) { +#if 0 + output_image_type = T4_IMAGE_TYPE_BILEVEL; + s->metadata.compression = compression; + select_tiff_compression(s, T4_IMAGE_TYPE_BILEVEL); + s->current_decoder = 0; + return 0; +#else switch (compression) { case T4_COMPRESSION_T4_1D: @@ -775,6 +841,7 @@ SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int compression) break; default: t4_t6_decode_init(&s->decoder.t4_t6, compression, s->metadata.image_width, s->row_handler, s->row_handler_user_data); + s->current_decoder = T4_COMPRESSION_T4_1D | T4_COMPRESSION_T4_2D | T4_COMPRESSION_T6; break; } s->metadata.compression = compression; @@ -789,14 +856,15 @@ SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int compression) break; default: t85_decode_init(&s->decoder.t85, s->row_handler, s->row_handler_user_data); + s->current_decoder = T4_COMPRESSION_T85 | T4_COMPRESSION_T85_L0; /* Constrain received images to the maximum width of any FAX. This will avoid one potential cause of trouble, where a bad received image has a gigantic dimension that sucks our memory dry. */ t85_decode_set_image_size_constraints(&s->decoder.t85, T4_WIDTH_1200_A3, 0); break; } - select_tiff_compression(s, T4_IMAGE_TYPE_BILEVEL); s->metadata.compression = compression; + select_tiff_compression(s, T4_IMAGE_TYPE_BILEVEL); return 0; #if defined(SPANDSP_SUPPORT_T88) case T4_COMPRESSION_T88: @@ -805,10 +873,12 @@ SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int compression) case T4_COMPRESSION_T88: break; default: + t88_decode_init(&s->decoder.t88, s->row_handler, s->row_handler_user_data); + s->current_decoder = T4_COMPRESSION_T88; break; } - select_tiff_compression(s, T4_IMAGE_TYPE_BILEVEL); s->metadata.compression = compression; + select_tiff_compression(s, T4_IMAGE_TYPE_BILEVEL); return 0; #endif case T4_COMPRESSION_T42_T81: @@ -820,6 +890,7 @@ SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int compression) break; default: t42_decode_init(&s->decoder.t42, s->row_handler, s->row_handler_user_data); + s->current_decoder = T4_COMPRESSION_T42_T81; /* Constrain received images to the maximum width of any FAX. This will avoid one potential cause of trouble, where a bad received image has a gigantic dimension that sucks our memory dry. */ @@ -837,6 +908,7 @@ SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int compression) break; default: t43_decode_init(&s->decoder.t43, s->row_handler, s->row_handler_user_data); + s->current_decoder = T4_COMPRESSION_T43; /* Constrain received images to the maximum width of any FAX. This will avoid one potential cause of trouble, where a bad received image has a gigantic dimension that sucks our memory dry. */ @@ -854,6 +926,8 @@ SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int compression) case T4_COMPRESSION_T45: break; default: + t45_decode_init(&s->decoder.t45, s->row_handler, s->row_handler_user_data); + s->current_decoder = T4_COMPRESSION_T45; break; } s->metadata.compression = compression; @@ -863,6 +937,7 @@ SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int compression) } return -1; +#endif } /*- End of function --------------------------------------------------------*/ @@ -876,14 +951,11 @@ SPAN_DECLARE(int) t4_rx_set_row_write_handler(t4_rx_state_t *s, t4_row_write_han { s->row_handler = handler; s->row_handler_user_data = user_data; - switch (s->metadata.compression) + switch (s->current_decoder) { - case T4_COMPRESSION_T4_1D: - case T4_COMPRESSION_T4_2D: - case T4_COMPRESSION_T6: + case T4_COMPRESSION_T4_1D | T4_COMPRESSION_T4_2D | T4_COMPRESSION_T6: return t4_t6_decode_set_row_write_handler(&s->decoder.t4_t6, handler, user_data); - case T4_COMPRESSION_T85: - case T4_COMPRESSION_T85_L0: + case T4_COMPRESSION_T85 | T4_COMPRESSION_T85_L0: return t85_decode_set_row_write_handler(&s->decoder.t85, handler, user_data); #if defined(SPANDSP_SUPPORT_T88) case T4_COMPRESSION_T88: @@ -914,12 +986,11 @@ SPAN_DECLARE(void) t4_rx_get_transfer_statistics(t4_rx_state_t *s, t4_stats_t *t t->image_y_resolution = s->metadata.y_resolution; t->x_resolution = s->metadata.x_resolution; t->y_resolution = s->metadata.y_resolution; + t->compression = s->metadata.compression; - switch (s->metadata.compression) + switch (s->current_decoder) { - case T4_COMPRESSION_T4_1D: - case T4_COMPRESSION_T4_2D: - case T4_COMPRESSION_T6: + case T4_COMPRESSION_T4_1D | T4_COMPRESSION_T4_2D | T4_COMPRESSION_T6: t->type = T4_IMAGE_TYPE_BILEVEL; t->width = t4_t6_decode_get_image_width(&s->decoder.t4_t6); t->length = t4_t6_decode_get_image_length(&s->decoder.t4_t6); @@ -930,8 +1001,7 @@ SPAN_DECLARE(void) t4_rx_get_transfer_statistics(t4_rx_state_t *s, t4_stats_t *t t->bad_rows = s->decoder.t4_t6.bad_rows; t->longest_bad_row_run = s->decoder.t4_t6.longest_bad_row_run; break; - case T4_COMPRESSION_T85: - case T4_COMPRESSION_T85_L0: + case T4_COMPRESSION_T85 | T4_COMPRESSION_T85_L0: t->type = T4_IMAGE_TYPE_BILEVEL; t->width = t85_decode_get_image_width(&s->decoder.t85); t->length = t85_decode_get_image_length(&s->decoder.t85); @@ -945,7 +1015,7 @@ SPAN_DECLARE(void) t4_rx_get_transfer_statistics(t4_rx_state_t *s, t4_stats_t *t break; #endif case T4_COMPRESSION_T42_T81: - t->type = T4_IMAGE_TYPE_COLOUR_8BIT; //T4_IMAGE_TYPE_GRAY_8BIT; + t->type = T4_IMAGE_TYPE_GRAY_8BIT; //T4_IMAGE_TYPE_COLOUR_8BIT; t->width = t42_decode_get_image_width(&s->decoder.t42); t->length = t42_decode_get_image_length(&s->decoder.t42); t->image_type = t->type; @@ -976,21 +1046,18 @@ SPAN_DECLARE(int) t4_rx_start_page(t4_rx_state_t *s) { span_log(&s->logging, SPAN_LOG_FLOW, "Start rx page %d - compression %s\n", s->current_page, t4_compression_to_str(s->metadata.compression)); - switch (s->metadata.compression) + switch (s->current_decoder) { case 0: s->pre_encoded_ptr = 0; s->pre_encoded_len = 0; s->image_put_handler = NULL; break; - case T4_COMPRESSION_T4_1D: - case T4_COMPRESSION_T4_2D: - case T4_COMPRESSION_T6: + case T4_COMPRESSION_T4_1D | T4_COMPRESSION_T4_2D | T4_COMPRESSION_T6: t4_t6_decode_restart(&s->decoder.t4_t6, s->metadata.image_width); s->image_put_handler = (t4_image_put_handler_t) t4_t6_decode_put; break; - case T4_COMPRESSION_T85: - case T4_COMPRESSION_T85_L0: + case T4_COMPRESSION_T85 | T4_COMPRESSION_T85_L0: t85_decode_restart(&s->decoder.t85); s->image_put_handler = (t4_image_put_handler_t) t85_decode_put; break; @@ -1036,7 +1103,7 @@ static int tiff_row_write_handler(void *user_data, const uint8_t buf[], size_t l { if (s->tiff.image_size + len >= s->tiff.image_buffer_size) { - if ((t = realloc(s->tiff.image_buffer, s->tiff.image_buffer_size + 100*len)) == NULL) + if ((t = span_realloc(s->tiff.image_buffer, s->tiff.image_buffer_size + 100*len)) == NULL) return -1; s->tiff.image_buffer_size += 100*len; s->tiff.image_buffer = t; @@ -1057,15 +1124,15 @@ SPAN_DECLARE(int) t4_rx_end_page(t4_rx_state_t *s) if (s->image_put_handler) s->image_put_handler((void *) &s->decoder, NULL, 0); - switch (s->metadata.compression) + switch (s->current_decoder) { - case T4_COMPRESSION_T4_1D: - case T4_COMPRESSION_T4_2D: - case T4_COMPRESSION_T6: + case 0: + length = s->pre_encoded_ptr; + break; + case T4_COMPRESSION_T4_1D | T4_COMPRESSION_T4_2D | T4_COMPRESSION_T6: length = t4_t6_decode_get_image_length(&s->decoder.t4_t6); break; - case T4_COMPRESSION_T85: - case T4_COMPRESSION_T85_L0: + case T4_COMPRESSION_T85 | T4_COMPRESSION_T85_L0: length = t85_decode_get_image_length(&s->decoder.t85); break; #if defined(SPANDSP_SUPPORT_T88) @@ -1100,6 +1167,7 @@ SPAN_DECLARE(int) t4_rx_end_page(t4_rx_state_t *s) if (write_tiff_image(s) == 0) s->current_page++; s->tiff.image_size = 0; + s->pre_encoded_ptr = 0; } else { @@ -1142,6 +1210,7 @@ SPAN_DECLARE(t4_rx_state_t *) t4_rx_init(t4_rx_state_t *s, const char *file, int s->metadata.y_resolution = T4_Y_RESOLUTION_FINE; s->current_page = 0; + s->current_decoder = 0; /* Default handler */ s->row_handler = tiff_row_write_handler; @@ -1153,7 +1222,7 @@ SPAN_DECLARE(t4_rx_state_t *) t4_rx_init(t4_rx_state_t *s, const char *file, int if (open_tiff_output_file(s, file) < 0) { if (allocated) - free(s); + span_free(s); return NULL; } /* Save the file name for logging reports. */ @@ -1167,14 +1236,11 @@ SPAN_DECLARE(int) t4_rx_release(t4_rx_state_t *s) { if (s->tiff.file) tiff_rx_release(s); - switch (s->metadata.compression) + switch (s->current_decoder) { - case T4_COMPRESSION_T4_1D: - case T4_COMPRESSION_T4_2D: - case T4_COMPRESSION_T6: + case T4_COMPRESSION_T4_1D | T4_COMPRESSION_T4_2D | T4_COMPRESSION_T6: return t4_t6_decode_release(&s->decoder.t4_t6); - case T4_COMPRESSION_T85: - case T4_COMPRESSION_T85_L0: + case T4_COMPRESSION_T85 | T4_COMPRESSION_T85_L0: return t85_decode_release(&s->decoder.t85); #if defined(SPANDSP_SUPPORT_T88) case T4_COMPRESSION_T88: @@ -1200,7 +1266,7 @@ SPAN_DECLARE(int) t4_rx_free(t4_rx_state_t *s) int ret; ret = t4_rx_release(s); - free(s); + span_free(s); return ret; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/t4_tx.c b/libs/spandsp/src/t4_tx.c index 9e8f3e678c..35d3632f60 100644 --- a/libs/spandsp/src/t4_tx.c +++ b/libs/spandsp/src/t4_tx.c @@ -96,41 +96,37 @@ typedef struct int bit_mask; } packer_t; -typedef struct -{ - float resolution; - int code; -} res_table_t; +static void t4_tx_set_image_type(t4_tx_state_t *s, int image_type); +static void set_image_width(t4_tx_state_t *s, uint32_t image_width); +static void set_image_length(t4_tx_state_t *s, uint32_t image_length); -static void t4_tx_set_image_length(t4_tx_state_t *s, uint32_t image_length); - -static const res_table_t x_res_table[] = +static const float x_res_table[] = { - { 100.0f/CM_PER_INCH, T4_X_RESOLUTION_100}, - { 102.0f/CM_PER_INCH, T4_X_RESOLUTION_R4}, - { 200.0f/CM_PER_INCH, T4_X_RESOLUTION_200}, - { 204.0f/CM_PER_INCH, T4_X_RESOLUTION_R8}, - { 300.0f/CM_PER_INCH, T4_X_RESOLUTION_300}, - { 400.0f/CM_PER_INCH, T4_X_RESOLUTION_400}, - { 408.0f/CM_PER_INCH, T4_X_RESOLUTION_R16}, - { 600.0f/CM_PER_INCH, T4_X_RESOLUTION_600}, - {1200.0f/CM_PER_INCH, T4_X_RESOLUTION_1200}, - { -1.00f, -1} + 100.0f*100.0f/CM_PER_INCH, + 102.0f*100.0f/CM_PER_INCH, + 200.0f*100.0f/CM_PER_INCH, + 204.0f*100.0f/CM_PER_INCH, + 300.0f*100.0f/CM_PER_INCH, + 400.0f*100.0f/CM_PER_INCH, + 408.0f*100.0f/CM_PER_INCH, + 600.0f*100.0f/CM_PER_INCH, + 1200.0f*100.0f/CM_PER_INCH, + -1.00f }; -static const res_table_t y_res_table[] = +static const float y_res_table[] = { - { 38.50f, T4_Y_RESOLUTION_STANDARD}, - { 100.0f/CM_PER_INCH, T4_Y_RESOLUTION_100}, - { 77.00f, T4_Y_RESOLUTION_FINE}, - { 200.0f/CM_PER_INCH, T4_Y_RESOLUTION_200}, - { 300.0f/CM_PER_INCH, T4_Y_RESOLUTION_300}, - { 154.00f, T4_Y_RESOLUTION_SUPERFINE}, - { 400.0f/CM_PER_INCH, T4_Y_RESOLUTION_400}, - { 600.0f/CM_PER_INCH, T4_Y_RESOLUTION_600}, - { 800.0f/CM_PER_INCH, T4_Y_RESOLUTION_800}, - {1200.0f/CM_PER_INCH, T4_Y_RESOLUTION_1200}, - { -1.00f, -1} + 38.50f*100.0f, + 100.0f*100.0f/CM_PER_INCH, + 77.00f*100.0f, + 200.0f*100.0f/CM_PER_INCH, + 300.0f*100.0f/CM_PER_INCH, + 154.00f*100.0f, + 400.0f*100.0f/CM_PER_INCH, + 600.0f*100.0f/CM_PER_INCH, + 800.0f*100.0f/CM_PER_INCH, + 1200.0f*100.0f/CM_PER_INCH, + -1.00f }; static const int resolution_map[10][9] = @@ -215,7 +211,65 @@ SPAN_DECLARE(void) TIFF_FX_init(void) /*- End of function --------------------------------------------------------*/ #endif -static int match_resolution(int res_unit, float actual, const res_table_t table[]) +static int code_to_x_resolution(int code) +{ + static const int xxx[] = + { + T4_X_RESOLUTION_R8, /* R8 x standard */ + T4_X_RESOLUTION_R8, /* R8 x fine */ + T4_X_RESOLUTION_R8, /* R8 x superfine */ + T4_X_RESOLUTION_R16, /* R16 x superfine */ + T4_X_RESOLUTION_100, /* 100x100 */ + T4_X_RESOLUTION_200, /* 200x100 */ + T4_X_RESOLUTION_200, /* 200x200 */ + T4_X_RESOLUTION_200, /* 200x400 */ + T4_X_RESOLUTION_300, /* 300x300 */ + T4_X_RESOLUTION_300, /* 300x600 */ + T4_X_RESOLUTION_400, /* 400x400 */ + T4_X_RESOLUTION_400, /* 400x800 */ + T4_X_RESOLUTION_600, /* 600x600 */ + T4_X_RESOLUTION_600, /* 600x1200 */ + T4_X_RESOLUTION_1200 /* 1200x1200 */ + }; + int entry; + + entry = top_bit(code); + if (entry < 0 || entry > 14) + return 0; + return xxx[entry]; +} +/*- End of function --------------------------------------------------------*/ + +static int code_to_y_resolution(int code) +{ + static const int yyy[] = + { + T4_Y_RESOLUTION_STANDARD, /* R8 x standard */ + T4_Y_RESOLUTION_FINE, /* R8 x fine */ + T4_Y_RESOLUTION_SUPERFINE, /* R8 x superfine */ + T4_Y_RESOLUTION_SUPERFINE, /* R16 x superfine */ + T4_Y_RESOLUTION_100, /* 100x100 */ + T4_Y_RESOLUTION_100, /* 200x100 */ + T4_Y_RESOLUTION_200, /* 200x200 */ + T4_Y_RESOLUTION_400, /* 200x400 */ + T4_Y_RESOLUTION_300, /* 300x300 */ + T4_Y_RESOLUTION_600, /* 300x600 */ + T4_Y_RESOLUTION_400, /* 400x400 */ + T4_Y_RESOLUTION_800, /* 400x800 */ + T4_Y_RESOLUTION_600, /* 600x600 */ + T4_Y_RESOLUTION_1200, /* 600x1200 */ + T4_Y_RESOLUTION_1200 /* 1200x1200 */ + }; + int entry; + + entry = top_bit(code); + if (entry < 0 || entry > 14) + return 0; + return yyy[entry]; +} +/*- End of function --------------------------------------------------------*/ + +static int match_resolution(float actual, const float table[]) { int i; int best_entry; @@ -225,16 +279,14 @@ static int match_resolution(int res_unit, float actual, const res_table_t table[ if (actual == 0.0f) return -1; - if (res_unit == RESUNIT_INCH) - actual /= CM_PER_INCH; best_ratio = 0.0f; best_entry = -1; - for (i = 0; table[i].code > 0; i++) + for (i = 0; table[i] > 0.0f; i++) { - if (actual > table[i].resolution) - ratio = table[i].resolution/actual; + if (actual > table[i]) + ratio = table[i]/actual; else - ratio = actual/table[i].resolution; + ratio = actual/table[i]; if (ratio > best_ratio) { best_entry = i; @@ -247,7 +299,51 @@ static int match_resolution(int res_unit, float actual, const res_table_t table[ } /*- End of function --------------------------------------------------------*/ -#if 0 //defined(SPANDSP_SUPPORT_TIFF_FX) +static int best_colour_resolution(float actual, int allowed_resolutions) +{ + static const struct + { + float resolution; + int resolution_code; + } x_res_table[] = + { + { 100.0f*100.0f/CM_PER_INCH, T4_RESOLUTION_100_100}, + { 200.0f*100.0f/CM_PER_INCH, T4_RESOLUTION_200_200}, + { 300.0f*100.0f/CM_PER_INCH, T4_RESOLUTION_300_300}, + { 400.0f*100.0f/CM_PER_INCH, T4_RESOLUTION_400_400}, + { 600.0f*100.0f/CM_PER_INCH, T4_RESOLUTION_600_600}, + {1200.0f*100.0f/CM_PER_INCH, T4_RESOLUTION_1200_1200}, + { -1.00f, -1} + }; + int i; + int best_entry; + float best_ratio; + float ratio; + + if (actual == 0.0f) + return -1; + + best_ratio = 0.0f; + best_entry = -1; + for (i = 0; x_res_table[i].resolution > 0.0f; i++) + { + if (!(allowed_resolutions & x_res_table[i].resolution_code)) + continue; + if (actual > x_res_table[i].resolution) + ratio = x_res_table[i].resolution/actual; + else + ratio = actual/x_res_table[i].resolution; + if (ratio > best_ratio) + { + best_entry = i; + best_ratio = ratio; + } + } + return x_res_table[best_entry].resolution_code; +} +/*- End of function --------------------------------------------------------*/ + +#if defined(SPANDSP_SUPPORT_TIFF_FX) static int read_colour_map(t4_tx_state_t *s, int bits_per_sample) { int i; @@ -266,7 +362,7 @@ static int read_colour_map(t4_tx_state_t *s, int bits_per_sample) /* TODO: This only allows for 8 bit deep maps */ span_log(&s->logging, SPAN_LOG_FLOW, "Got a colour map\n"); s->colour_map_entries = 1 << bits_per_sample; - if ((s->colour_map = realloc(s->colour_map, 3*s->colour_map_entries)) == NULL) + if ((s->colour_map = span_realloc(s->colour_map, 3*s->colour_map_entries)) == NULL) return -1; #if 0 /* Sweep the colormap in the proper order */ @@ -286,7 +382,7 @@ static int read_colour_map(t4_tx_state_t *s, int bits_per_sample) s->colour_map[2*s->colour_map_entries + i] = (map_b[i] >> 8) & 0xFF; } #endif - lab_to_srgb(&s->lab_params, s->colour_map, s->colour_map, 256); + lab_to_srgb(&s->lab_params, s->colour_map, s->colour_map, s->colour_map_entries); for (i = 0; i < s->colour_map_entries; i++) span_log(&s->logging, SPAN_LOG_FLOW, "Map %3d - %5d %5d %5d\n", i, s->colour_map[3*i], s->colour_map[3*i + 1], s->colour_map[3*i + 2]); return 0; @@ -309,8 +405,18 @@ static int get_tiff_directory_info(t4_tx_state_t *s) }; char *u; char uu[10]; + float *fl_parms; uint64_t diroff; + float lmin; + float lmax; + float amin; + float amax; + float bmin; + float bmax; uint8_t parm8; +#endif +#if defined(TIFFTAG_INDEXED) + uint16_t parm16; #endif uint32_t parm32; int best_x_entry; @@ -321,6 +427,8 @@ static int get_tiff_directory_info(t4_tx_state_t *s) uint16_t bits_per_sample; uint16_t samples_per_pixel; uint16_t res_unit; + uint16_t YCbCrSubsample_horiz; + uint16_t YCbCrSubsample_vert; t = &s->tiff; bits_per_sample = 1; @@ -331,6 +439,8 @@ static int get_tiff_directory_info(t4_tx_state_t *s) t->image_type = T4_IMAGE_TYPE_BILEVEL; else if (samples_per_pixel == 3 && bits_per_sample == 1) t->image_type = T4_IMAGE_TYPE_COLOUR_BILEVEL; + else if (samples_per_pixel == 4 && bits_per_sample == 1) + t->image_type = T4_IMAGE_TYPE_COLOUR_BILEVEL; else if (samples_per_pixel == 1 && bits_per_sample == 8) t->image_type = T4_IMAGE_TYPE_GRAY_8BIT; else if (samples_per_pixel == 1 && bits_per_sample > 8) @@ -341,62 +451,111 @@ static int get_tiff_directory_info(t4_tx_state_t *s) t->image_type = T4_IMAGE_TYPE_COLOUR_12BIT; else return -1; -#if 0 - /* Limit ourselves to plain black and white pages */ - if (t->image_type != T4_IMAGE_TYPE_BILEVEL) - return -1; + +#if defined(TIFFTAG_INDEXED) + parm16 = 0; + if (TIFFGetField(t->tiff_file, TIFFTAG_INDEXED, &parm16)) + { + span_log(&s->logging, SPAN_LOG_FLOW, "Indexed %s (%u)\n", (parm16) ? "palette image" : "non-palette image", parm16); + if (parm16 == 1) + { + /* Its an indexed image, so its really a colour image, even though it may have only one sample per pixel */ + if (samples_per_pixel == 1 && bits_per_sample == 8) + t->image_type = T4_IMAGE_TYPE_COLOUR_8BIT; + else if (samples_per_pixel == 1 && bits_per_sample > 8) + t->image_type = T4_IMAGE_TYPE_COLOUR_12BIT; + } + } #endif + parm32 = 0; TIFFGetField(t->tiff_file, TIFFTAG_IMAGEWIDTH, &parm32); - t->image_width = - s->metadata.image_width = parm32; + t->image_width = parm32; parm32 = 0; TIFFGetField(t->tiff_file, TIFFTAG_IMAGELENGTH, &parm32); - t->image_length = - s->metadata.image_length = parm32; + t->image_length = parm32; + x_resolution = 0.0f; TIFFGetField(t->tiff_file, TIFFTAG_XRESOLUTION, &x_resolution); y_resolution = 0.0f; TIFFGetField(t->tiff_file, TIFFTAG_YRESOLUTION, &y_resolution); res_unit = RESUNIT_INCH; TIFFGetField(t->tiff_file, TIFFTAG_RESOLUTIONUNIT, &res_unit); + + t->x_resolution = x_resolution*100.0f; + t->y_resolution = y_resolution*100.0f; + if (res_unit == RESUNIT_INCH) + { + t->x_resolution /= CM_PER_INCH; + t->y_resolution /= CM_PER_INCH; + } + + if (((best_x_entry = match_resolution(t->x_resolution, x_res_table)) >= 0) + && + ((best_y_entry = match_resolution(t->y_resolution, y_res_table)) >= 0)) + { + t->resolution_code = resolution_map[best_y_entry][best_x_entry]; + } + else + { + t->resolution_code = 0; + } + t->photo_metric = PHOTOMETRIC_MINISWHITE; TIFFGetField(t->tiff_file, TIFFTAG_PHOTOMETRIC, &t->photo_metric); - set_lab_illuminant(&s->lab_params, 0.9638f, 1.0f, 0.8245f); + /* The default luminant is D50 */ + set_lab_illuminant(&s->lab_params, 96.422f, 100.000f, 82.521f); set_lab_gamut(&s->lab_params, 0, 100, -85, 85, -75, 125, FALSE); t->compression = -1; TIFFGetField(t->tiff_file, TIFFTAG_COMPRESSION, &t->compression); + switch (t->compression) + { + case COMPRESSION_CCITT_T4: + span_log(&s->logging, SPAN_LOG_FLOW, "T.4\n"); + break; + case COMPRESSION_CCITT_T6: + span_log(&s->logging, SPAN_LOG_FLOW, "T.6\n"); + break; + case COMPRESSION_T85: + span_log(&s->logging, SPAN_LOG_FLOW, "T.85\n"); + break; +#if defined(SPANDSP_SUPPORT_T43) + case COMPRESSION_T43: + span_log(&s->logging, SPAN_LOG_FLOW, "T.43\n"); + break; +#endif + case COMPRESSION_JPEG: + span_log(&s->logging, SPAN_LOG_FLOW, "JPEG\n"); + if (t->photo_metric == PHOTOMETRIC_ITULAB) + span_log(&s->logging, SPAN_LOG_FLOW, "ITULAB\n"); + break; + case COMPRESSION_NONE: + span_log(&s->logging, SPAN_LOG_FLOW, "No compression\n"); + break; + default: + span_log(&s->logging, SPAN_LOG_FLOW, "Unexpected compression %d\n", t->compression); + break; + } + +#if defined(SPANDSP_SUPPORT_TIFF_FX) + read_colour_map(s, bits_per_sample); +#endif + + YCbCrSubsample_horiz = 0; + YCbCrSubsample_vert = 0; + if (TIFFGetField(t->tiff_file, TIFFTAG_YCBCRSUBSAMPLING, &YCbCrSubsample_horiz, &YCbCrSubsample_vert)) + span_log(&s->logging, SPAN_LOG_FLOW, "Subsampling %d %d\n", YCbCrSubsample_horiz, YCbCrSubsample_vert); + t->fill_order = FILLORDER_LSB2MSB; - if (res_unit == RESUNIT_INCH) - t->x_resolution = x_resolution*100.0f/CM_PER_INCH; - else - t->x_resolution = x_resolution*100.0f; - /* Treat everything we can't match as R8. Most FAXes are this resolution anyway. */ - if ((best_x_entry = match_resolution(res_unit, x_resolution, x_res_table)) < 0) - best_x_entry = 3; - s->metadata.x_resolution = x_res_table[best_x_entry].code; - - if (res_unit == RESUNIT_INCH) - t->y_resolution = y_resolution*100.0f/CM_PER_INCH; - else - t->y_resolution = y_resolution*100.0f; - if ((best_y_entry = match_resolution(res_unit, y_resolution, y_res_table)) < 0) - best_y_entry = 0; - s->metadata.y_resolution = y_res_table[best_y_entry].code; - - s->metadata.resolution_code = resolution_map[best_y_entry][best_x_entry]; - - t4_tx_set_image_width(s, s->metadata.image_width); - t4_tx_set_image_length(s, s->metadata.image_length); - t4_tx_set_max_2d_rows_per_1d_row(s, -s->metadata.y_resolution); #if defined(SPANDSP_SUPPORT_TIFF_FX) if (TIFFGetField(t->tiff_file, TIFFTAG_PROFILETYPE, &parm32)) span_log(&s->logging, SPAN_LOG_FLOW, "Profile type %u\n", parm32); if (TIFFGetField(t->tiff_file, TIFFTAG_FAXPROFILE, &parm8)) span_log(&s->logging, SPAN_LOG_FLOW, "FAX profile %s (%u)\n", tiff_fx_fax_profiles[parm8], parm8); + if (TIFFGetField(t->tiff_file, TIFFTAG_CODINGMETHODS, &parm32)) span_log(&s->logging, SPAN_LOG_FLOW, "Coding methods 0x%x\n", parm32); if (TIFFGetField(t->tiff_file, TIFFTAG_VERSIONYEAR, &u)) @@ -408,11 +567,60 @@ static int get_tiff_directory_info(t4_tx_state_t *s) if (TIFFGetField(t->tiff_file, TIFFTAG_MODENUMBER, &parm8)) span_log(&s->logging, SPAN_LOG_FLOW, "Mode number %u\n", parm8); + switch (t->photo_metric) + { + case PHOTOMETRIC_ITULAB: +#if 1 + /* 8 bit version */ + lmin = 0.0f; + lmax = 100.0f; + amin = -21760.0f/255.0f; + amax = 21590.0f/255.0f; + bmin = -19200.0f/255.0f; + bmax = 31800.0f/255.0f; +#else + /* 12 bit version */ + lmin = 0.0f; + lmax = 100.0f; + amin = -348160.0f/4095.0f + amax = 347990.0f/4095.0f + bmin = -307200.0f/4095.0f + bmax = 511800.0f/4095.0f +#endif + break; + default: + lmin = 0.0f; + lmax = 0.0f; + amin = 0.0f; + amax = 0.0f; + bmin = 0.0f; + bmax = 0.0f; + break; + } + + if (TIFFGetField(t->tiff_file, TIFFTAG_DECODE, &parm16, &fl_parms)) + { + lmin = fl_parms[0]; + lmax = fl_parms[1]; + amin = fl_parms[2]; + amax = fl_parms[3]; + bmin = fl_parms[4]; + bmax = fl_parms[5]; + span_log(&s->logging, SPAN_LOG_FLOW, "Got decode tag %f %f %f %f %f %f\n", lmin, lmax, amin, amax, bmin, bmax); + } + + /* TIFFTAG_IMAGEBASECOLOR */ + + if (TIFFGetField(t->tiff_file, TIFFTAG_T82OPTIONS, &parm32)) + span_log(&s->logging, SPAN_LOG_FLOW, "T.82 options 0x%x\n", parm32); + + /* TIFFTAG_STRIPROWCOUNTS */ + /* TIFFTAG_IMAGELAYER */ + /* If global parameters are present they should only be on the first page of the file. However, as we scan the file we might as well look for them on any page. */ if (TIFFGetField(t->tiff_file, TIFFTAG_GLOBALPARAMETERSIFD, &diroff)) { - span_log(&s->logging, SPAN_LOG_FLOW, "Global parameters IFD at %" PRIu64 "\n", diroff); if (!TIFFReadCustomDirectory(t->tiff_file, diroff, &tiff_fx_field_array)) { span_log(&s->logging, SPAN_LOG_FLOW, "Global parameter read failed\n"); @@ -451,8 +659,6 @@ static int test_tiff_directory_info(t4_tx_state_t *s) uint16_t bits_per_sample; uint16_t samples_per_pixel; int image_type; - int best_x_entry; - int best_y_entry; float x_resolution; float y_resolution; t4_tx_tiff_state_t *t; @@ -466,6 +672,8 @@ static int test_tiff_directory_info(t4_tx_state_t *s) image_type = T4_IMAGE_TYPE_BILEVEL; else if (samples_per_pixel == 3 && bits_per_sample == 1) image_type = T4_IMAGE_TYPE_COLOUR_BILEVEL; + else if (samples_per_pixel == 4 && bits_per_sample == 1) + image_type = T4_IMAGE_TYPE_COLOUR_BILEVEL; else if (samples_per_pixel == 1 && bits_per_sample == 8) image_type = T4_IMAGE_TYPE_GRAY_8BIT; else if (samples_per_pixel == 1 && bits_per_sample > 8) @@ -476,18 +684,14 @@ static int test_tiff_directory_info(t4_tx_state_t *s) image_type = T4_IMAGE_TYPE_COLOUR_12BIT; else image_type = -1; -#if 0 - /* Limit ourselves to plain black and white pages */ - if (t->image_type != T4_IMAGE_TYPE_BILEVEL) - return -1; -#endif if (t->image_type != image_type) return 1; parm32 = 0; TIFFGetField(t->tiff_file, TIFFTAG_IMAGEWIDTH, &parm32); if (s->tiff.image_width != (int) parm32) - return 1; + return 2; + x_resolution = 0.0f; TIFFGetField(t->tiff_file, TIFFTAG_XRESOLUTION, &x_resolution); y_resolution = 0.0f; @@ -495,16 +699,17 @@ static int test_tiff_directory_info(t4_tx_state_t *s) res_unit = RESUNIT_INCH; TIFFGetField(t->tiff_file, TIFFTAG_RESOLUTIONUNIT, &res_unit); - /* Treat everything we can't match as R8. Most FAXes are this resolution anyway. */ - if ((best_x_entry = match_resolution(res_unit, x_resolution, x_res_table)) < 0) - return 1; - if (s->metadata.x_resolution != x_res_table[best_x_entry].code) - return 1; - - if ((best_y_entry = match_resolution(res_unit, y_resolution, y_res_table)) < 0) - return 1; - if (s->metadata.y_resolution != y_res_table[best_y_entry].code) - return 1; + x_resolution *= 100.0f; + y_resolution *= 100.0f; + if (res_unit == RESUNIT_INCH) + { + x_resolution /= CM_PER_INCH; + y_resolution /= CM_PER_INCH; + } + if (s->tiff.x_resolution != (int) x_resolution) + return 3; + if (s->tiff.y_resolution != (int) y_resolution) + return 4; return 0; } @@ -535,6 +740,19 @@ static int open_tiff_input_file(t4_tx_state_t *s, const char *file) } /*- End of function --------------------------------------------------------*/ +static int metadata_row_read_handler(void *user_data, uint8_t buf[], size_t len) +{ + t4_tx_state_t *s; + + s = (t4_tx_state_t *) user_data; + if (s->tiff.row >= s->metadata.image_length) + return 0; + memcpy(buf, &s->tiff.image_buffer[s->tiff.row*len], len); + s->tiff.row++; + return len; +} +/*- End of function --------------------------------------------------------*/ + static int tiff_row_read_handler(void *user_data, uint8_t buf[], size_t len) { t4_tx_state_t *s; @@ -544,6 +762,11 @@ static int tiff_row_read_handler(void *user_data, uint8_t buf[], size_t len) s = (t4_tx_state_t *) user_data; if (s->tiff.row >= s->tiff.image_length) return 0; + if (s->tiff.image_buffer == NULL) + { + exit(2); + return 0; + } memcpy(buf, &s->tiff.image_buffer[s->tiff.row*len], len); s->tiff.row++; @@ -551,7 +774,7 @@ static int tiff_row_read_handler(void *user_data, uint8_t buf[], size_t len) far end will accept, we need to squash it down to size. */ for (i = 1; i < s->row_squashing_ratio && s->tiff.row < s->tiff.image_length; i++) { - for (j = 0; j < s->tiff.image_width/8; j++) + for (j = 0; j < len; j++) buf[j] |= s->tiff.image_buffer[s->tiff.row*len + j]; s->tiff.row++; } @@ -559,19 +782,52 @@ static int tiff_row_read_handler(void *user_data, uint8_t buf[], size_t len) } /*- End of function --------------------------------------------------------*/ -static int row_read(void *user_data, uint8_t buf[], size_t len) +static int translate_row_read2(void *user_data, uint8_t buf[], size_t len) { t4_tx_state_t *s; + s = (t4_tx_state_t *) user_data; + memcpy(buf, &s->pack_buf[s->pack_ptr], len); + s->pack_ptr += len; + s->pack_row++; + return len; +} +/*- End of function --------------------------------------------------------*/ + +static int translate_row_read(void *user_data, uint8_t buf[], size_t len) +{ + t4_tx_state_t *s; + int i; + int j; + s = (t4_tx_state_t *) user_data; if (s->tiff.raw_row >= s->tiff.image_length) return 0; + if (TIFFReadScanline(s->tiff.tiff_file, buf, s->tiff.raw_row, 0) < 0) return 0; + s->tiff.raw_row++; + + /* If this is a bi-level image which is stretched more vertically than we are able + to send we need to squash it down to size. */ + for (i = 1; i < s->row_squashing_ratio; i++) + { +#if defined(_MSC_VER) + uint8_t *extra_buf = (uint8_t *) _alloca(len); +#else + uint8_t extra_buf[len]; +#endif + + if (TIFFReadScanline(s->tiff.tiff_file, extra_buf, s->tiff.raw_row, 0) < 0) + return 0; + s->tiff.raw_row++; + /* We know this is a bi-level image if we are squashing */ + for (j = 0; j < s->tiff.image_width/8; j++) + buf[j] |= extra_buf[s->tiff.image_width/8 + j]; + } if (s->apply_lab) lab_to_srgb(&s->lab_params, buf, buf, len/3); - s->tiff.raw_row++; return len; } /*- End of function --------------------------------------------------------*/ @@ -601,6 +857,35 @@ static int embedded_comment_handler(void *user_data, const uint8_t buf[], size_t } /*- End of function --------------------------------------------------------*/ +static int read_tiff_raw_image(t4_tx_state_t *s) +{ + int num_strips; + int total_len; + int len; + int i; + + num_strips = TIFFNumberOfStrips(s->tiff.tiff_file); + total_len = 0; + for (i = 0; i < num_strips; i++) + total_len += TIFFRawStripSize(s->tiff.tiff_file, i); + if ((s->pre_encoded_buf = span_realloc(s->pre_encoded_buf, total_len)) == NULL) + return -1; + total_len = 0; + for (i = 0; i < num_strips; i++, total_len += len) + { + len = TIFFRawStripSize(s->tiff.tiff_file, i); + if ((len = TIFFReadRawStrip(s->tiff.tiff_file, i, &s->pre_encoded_buf[total_len], len)) < 0) + { + span_log(&s->logging, SPAN_LOG_WARNING, "%s: TIFFReadRawStrip error.\n", s->tiff.file); + return -1; + } + } + s->pre_encoded_len = total_len; + s->pre_encoded_ptr = 0; + return 0; +} +/*- End of function --------------------------------------------------------*/ + static int read_tiff_t85_image(t4_tx_state_t *s) { int biggest; @@ -628,9 +913,9 @@ static int read_tiff_t85_image(t4_tx_state_t *s) s->tiff.image_size = s->tiff.image_length*((s->tiff.image_width + 7)/8); if (s->tiff.image_size >= s->tiff.image_buffer_size) { - if ((t = realloc(s->tiff.image_buffer, s->tiff.image_size)) == NULL) + if ((t = span_realloc(s->tiff.image_buffer, s->tiff.image_size)) == NULL) { - free(raw_data); + span_free(raw_data); return -1; } s->tiff.image_buffer_size = s->tiff.image_size; @@ -639,6 +924,7 @@ static int read_tiff_t85_image(t4_tx_state_t *s) pack.buf = s->tiff.image_buffer; pack.ptr = 0; + pack.size = s->tiff.image_size; pack.row = 0; t85_decode_init(&t85, packing_row_write_handler, &pack); t85_decode_set_comment_handler(&t85, 1000, embedded_comment_handler, s); @@ -650,7 +936,7 @@ static int read_tiff_t85_image(t4_tx_state_t *s) if ((len = TIFFReadRawStrip(s->tiff.tiff_file, i, raw_data, len)) < 0) { span_log(&s->logging, SPAN_LOG_WARNING, "%s: TIFFReadRawStrip error.\n", s->tiff.file); - free(raw_data); + span_free(raw_data); return -1; } result = t85_decode_put(&t85, raw_data, len); @@ -663,40 +949,55 @@ static int read_tiff_t85_image(t4_tx_state_t *s) len = t85_decode_get_compressed_image_size(&t85); span_log(&s->logging, SPAN_LOG_WARNING, "Compressed image is %d bytes, %d rows\n", len/8, s->tiff.image_length); t85_decode_release(&t85); - free(raw_data); + span_free(raw_data); return 0; } /*- End of function --------------------------------------------------------*/ #if defined(SPANDSP_SUPPORT_T43) -static int read_tiff_t43_image(t4_tx_state_t *s, uint8_t **buf) +static int read_tiff_t43_image(t4_tx_state_t *s) { + int biggest; int num_strips; - int total_len; int len; int i; - int total_image_len; - int image_size; - logging_state_t *logging; + int result; + uint8_t *t; uint8_t *raw_data; + logging_state_t *logging; t43_decode_state_t t43; packer_t pack; + uint16_t bits_per_sample; + uint16_t samples_per_pixel; + + bits_per_sample = 1; + TIFFGetField(s->tiff.tiff_file, TIFFTAG_BITSPERSAMPLE, &bits_per_sample); + samples_per_pixel = 3; + TIFFGetField(s->tiff.tiff_file, TIFFTAG_SAMPLESPERPIXEL, &samples_per_pixel); + + samples_per_pixel = 3; num_strips = TIFFNumberOfStrips(s->tiff.tiff_file); - total_image_len = 0; + biggest = 0; for (i = 0; i < num_strips; i++) - total_image_len += TIFFRawStripSize(s->tiff.tiff_file, i); - if ((raw_data = span_alloc(total_image_len)) == NULL) + { + len = TIFFRawStripSize(s->tiff.tiff_file, i); + if (len > biggest) + biggest = len; + } + if ((raw_data = span_alloc(biggest)) == NULL) return -1; - total_len = 0; - for (i = 0; i < num_strips; i++, total_len += len) + s->tiff.image_size = samples_per_pixel*s->tiff.image_width*s->tiff.image_length; + if (s->tiff.image_size >= s->tiff.image_buffer_size) { - if ((len = TIFFReadRawStrip(s->tiff.tiff_file, i, &raw_data[total_len], total_image_len - total_len)) < 0) + if ((t = span_realloc(s->tiff.image_buffer, s->tiff.image_size)) == NULL) { - span_log(&s->logging, SPAN_LOG_FLOW, "TIFF read error.\n"); + span_free(raw_data); return -1; } + s->tiff.image_buffer_size = s->tiff.image_size; + s->tiff.image_buffer = t; } t43_decode_init(&t43, packing_row_write_handler, &pack); @@ -704,22 +1005,35 @@ static int read_tiff_t43_image(t4_tx_state_t *s, uint8_t **buf) logging = t43_decode_get_logging_state(&t43); span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); - image_size = 3*s->metadata.image_length*s->metadata.image_width; - if ((*buf = span_alloc(image_size)) == NULL) - return -1; - - pack.buf = *buf; + pack.buf = s->tiff.image_buffer; pack.ptr = 0; + pack.size = s->tiff.image_size; pack.row = 0; - t43_decode_put(&t43, raw_data, total_len); + + result = -1; + for (i = 0; i < num_strips; i++) + { + len = TIFFRawStripSize(s->tiff.tiff_file, i); + if ((len = TIFFReadRawStrip(s->tiff.tiff_file, i, raw_data, len)) < 0) + { + span_log(&s->logging, SPAN_LOG_WARNING, "%s: TIFFReadRawStrip error.\n", s->tiff.file); + span_free(raw_data); + return -1; + } + result = t43_decode_put(&t43, raw_data, len); + if (result != T4_DECODE_MORE_DATA) + break; + } + if (result == T4_DECODE_MORE_DATA) + result = t43_decode_put(&t43, NULL, 0); + t43_decode_release(&t43); - free(raw_data); - return image_size; + span_free(raw_data); + return s->tiff.image_size; } /*- End of function --------------------------------------------------------*/ #endif -#if 0 static int read_tiff_t42_t81_image(t4_tx_state_t *s) { int total_len; @@ -763,7 +1077,7 @@ static int read_tiff_t42_t81_image(t4_tx_state_t *s) if ((len = TIFFReadRawStrip(s->tiff.tiff_file, i, &raw_data[total_len], total_image_len - total_len)) < 0) { span_log(&s->logging, SPAN_LOG_WARNING, "%s: TIFFReadRawStrip error.\n", s->tiff.file); - free(raw_data); + span_free(raw_data); return -1; } } @@ -776,9 +1090,9 @@ static int read_tiff_t42_t81_image(t4_tx_state_t *s) s->tiff.image_size = samples_per_pixel*s->tiff.image_width*s->tiff.image_length; if (s->tiff.image_size >= s->tiff.image_buffer_size) { - if ((t = realloc(s->tiff.image_buffer, s->tiff.image_size)) == NULL) + if ((t = span_realloc(s->tiff.image_buffer, s->tiff.image_size)) == NULL) { - free(raw_data); + span_free(raw_data); return -1; } s->tiff.image_buffer_size = s->tiff.image_size; @@ -795,11 +1109,10 @@ static int read_tiff_t42_t81_image(t4_tx_state_t *s) t42_decode_put(&t42, NULL, 0); t42_decode_release(&t42); - free(raw_data); + span_free(raw_data); return s->tiff.image_size; } /*- End of function --------------------------------------------------------*/ -#endif static int read_tiff_decompressed_image(t4_tx_state_t *s) { @@ -814,7 +1127,7 @@ static int read_tiff_decompressed_image(t4_tx_state_t *s) s->tiff.image_size = s->tiff.image_length*TIFFScanlineSize(s->tiff.tiff_file); if (s->tiff.image_size >= s->tiff.image_buffer_size) { - if ((t = realloc(s->tiff.image_buffer, s->tiff.image_size)) == NULL) + if ((t = span_realloc(s->tiff.image_buffer, s->tiff.image_size)) == NULL) return -1; s->tiff.image_buffer_size = s->tiff.image_size; s->tiff.image_buffer = t; @@ -831,7 +1144,7 @@ static int read_tiff_decompressed_image(t4_tx_state_t *s) } } /* We might need to flip all the bits, so 1 = black and 0 = white. */ - if (s->tiff.photo_metric != PHOTOMETRIC_MINISWHITE) + if (s->tiff.image_type == T4_IMAGE_TYPE_BILEVEL && s->tiff.photo_metric != PHOTOMETRIC_MINISWHITE) { span_log(&s->logging, SPAN_LOG_FLOW, "%s: Photometric needs swapping.\n", s->tiff.file); for (i = 0; i < s->tiff.image_size; i++) @@ -849,50 +1162,160 @@ static int read_tiff_image(t4_tx_state_t *s) { int total_len; int i; + int len; uint8_t *t; - image_translate_state_t *translator; + + if (s->metadata.image_type != s->tiff.image_type || s->metadata.image_width != s->tiff.image_width) + { + image_translate_restart(&s->translator, s->tiff.image_length); + s->metadata.image_length = image_translate_get_output_length(&s->translator); + } + else + { + s->metadata.image_length = s->tiff.image_length; + } + s->pack_buf = NULL; + s->pack_ptr = 0; + s->pack_row = 0; if (s->tiff.image_type != T4_IMAGE_TYPE_BILEVEL) { - /* We need to dither this image down to pure black and white, possibly resizing it - along the way. */ - if ((translator = image_translate_init(NULL, T4_IMAGE_TYPE_BILEVEL, 1728, -1, s->tiff.image_type, s->metadata.image_width, s->metadata.image_length, row_read, s)) == NULL) - return -1; - s->metadata.image_width = image_translate_get_output_width(translator); - s->metadata.image_length = image_translate_get_output_length(translator); - s->metadata.x_resolution = T4_X_RESOLUTION_R8; - s->metadata.y_resolution = T4_Y_RESOLUTION_FINE; - s->metadata.resolution_code = T4_RESOLUTION_R8_FINE; - s->tiff.image_size = (s->metadata.image_width*s->metadata.image_length + 7)/8; - if (s->tiff.image_size >= s->tiff.image_buffer_size) + /* If colour/gray scale is supported we may be able to send the image as it is, perhaps after + a resizing. Otherwise we need to resize it, and squash it to a bilevel image. */ + if (s->tiff.compression == COMPRESSION_JPEG && s->tiff.photo_metric == PHOTOMETRIC_ITULAB) { - if ((t = realloc(s->tiff.image_buffer, s->tiff.image_size)) == NULL) - return -1; - s->tiff.image_buffer_size = s->tiff.image_size; - s->tiff.image_buffer = t; + if (s->metadata.image_type != s->tiff.image_type || s->metadata.image_width != s->tiff.image_width) + { + if (read_tiff_t42_t81_image(s) < 0) + return -1; + + s->pack_buf = s->tiff.image_buffer; + s->pack_ptr = 0; + s->pack_row = 0; + image_translate_set_row_read_handler(&s->translator, translate_row_read2, s); + } + else + { + /* Read the raw image, and send it as is */ + if (read_tiff_raw_image(s) < 0) + return -1; + } } - s->tiff.raw_row = 0; - switch (s->tiff.photo_metric) +#if defined(SPANDSP_SUPPORT_T43) + else if (s->tiff.compression == COMPRESSION_T43) { - case PHOTOMETRIC_CIELAB: - /* The default luminant is D50 */ - set_lab_illuminant(&s->lab_params, 0.96422f, 1.0f, 0.82521f); - set_lab_gamut(&s->lab_params, 0, 100, -128, 127, -128, 127, TRUE); - s->apply_lab = TRUE; - break; - case PHOTOMETRIC_ITULAB: - set_lab_illuminant(&s->lab_params, 0.9638f, 1.0f, 0.8245f); - set_lab_gamut(&s->lab_params, 0, 100, -85, 85, -75, 125, FALSE); - s->apply_lab = TRUE; - break; - default: - s->apply_lab = FALSE; - break; + if (s->metadata.image_type != s->tiff.image_type || s->metadata.image_width != s->tiff.image_width) + { + if ((len = read_tiff_t43_image(s)) < 0) + return -1; + + s->pack_buf = s->tiff.image_buffer; + s->pack_ptr = 0; + s->pack_row = 0; + image_translate_set_row_read_handler(&s->translator, translate_row_read2, s); + } + else + { + /* Read the raw image, and send it as is */ + if (read_tiff_raw_image(s) < 0) + return -1; + } + } +#endif +#if defined(SPANDSP_SUPPORT_T45) + else if (s->tiff.compression == COMPRESSION_T45) + { + if (s->metadata.image_type != s->tiff.image_type || s->metadata.image_width != s->tiff.image_width) + { + if (read_tiff_t45_image(s) < 0) + return -1; + + s->pack_buf = s->tiff.image_buffer; + s->pack_ptr = 0; + s->pack_row = 0; + image_translate_set_row_read_handler(&s->translator, translate_row_read2, s); + } + else + { + /* Read the raw image, and send it as is */ + if (read_tiff_raw_image(s) < 0) + return -1; + } + } +#endif + else + { + /* Let libtiff handle the decompression */ + TIFFSetField(s->tiff.tiff_file, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB); + if (s->metadata.image_type != s->tiff.image_type || s->metadata.image_width != s->tiff.image_width) + { + image_translate_set_row_read_handler(&s->translator, translate_row_read, s); + } + else + { + if (read_tiff_decompressed_image(s) < 0) + return -1; + } + } + set_image_width(s, s->metadata.image_width); + set_image_length(s, s->metadata.image_length); + t4_tx_set_image_type(s, s->metadata.image_type); + if (s->metadata.image_type == T4_IMAGE_TYPE_BILEVEL) + { + /* We need to dither this image down to pure black and white, possibly resizing it + along the way. */ + s->tiff.image_size = (s->metadata.image_width*s->metadata.image_length + 7)/8; + if (s->tiff.image_size >= s->tiff.image_buffer_size) + { + if ((t = span_realloc(s->tiff.image_buffer, s->tiff.image_size)) == NULL) + return -1; + s->tiff.image_buffer_size = s->tiff.image_size; + s->tiff.image_buffer = t; + } + s->tiff.raw_row = 0; + switch (s->tiff.photo_metric) + { + case PHOTOMETRIC_CIELAB: + /* The default luminant is D50 */ + set_lab_illuminant(&s->lab_params, 96.422f, 100.000f, 82.521f); + set_lab_gamut(&s->lab_params, 0, 100, -128, 127, -128, 127, TRUE); + s->apply_lab = TRUE; + break; + case PHOTOMETRIC_ITULAB: + /* The default luminant is D50 */ + set_lab_illuminant(&s->lab_params, 96.422f, 100.000f, 82.521f); + set_lab_gamut(&s->lab_params, 0, 100, -85, 85, -75, 125, FALSE); + s->apply_lab = TRUE; + break; + default: + s->apply_lab = FALSE; + break; + } + total_len = 0; + for (i = 0; i < s->metadata.image_length; i++) + total_len += image_translate_row(&s->translator, &s->tiff.image_buffer[total_len], s->metadata.image_width/8); + image_translate_release(&s->translator); + s->row_handler = metadata_row_read_handler; + s->row_handler_user_data = (void *) s; + } + else + { + if (s->metadata.image_type != s->tiff.image_type || s->metadata.image_width != s->tiff.image_width) + { + total_len = 0; + s->tiff.image_buffer = span_realloc(s->tiff.image_buffer, s->metadata.image_width*s->metadata.image_length*3); + for (i = 0; i < s->metadata.image_length; i++) + total_len += image_translate_row(&s->translator, &s->tiff.image_buffer[total_len], s->metadata.image_width); + image_translate_release(&s->translator); + s->row_handler = metadata_row_read_handler; + s->row_handler_user_data = (void *) s; + } + else + { + s->row_handler = tiff_row_read_handler; + s->row_handler_user_data = (void *) s; + } } - total_len = 0; - for (i = 0; i < s->metadata.image_length; i++) - total_len += image_translate_row(translator, &s->tiff.image_buffer[total_len], s->metadata.image_width/8); - image_translate_free(translator); } else { @@ -903,13 +1326,59 @@ static int read_tiff_image(t4_tx_state_t *s) slightly long one, but lets not bother. */ switch (s->tiff.compression) { - case COMPRESSION_T85: - /* Decode the whole image into a buffer */ - /* libtiff probably cannot decompress T.85, so we must handle it ourselves */ - /* Decode the whole image into a buffer */ - if (read_tiff_t85_image(s) < 0) - return -1; +#if defined(SPANDSP_SUPPORT_T88) + case COMPRESSION_T88: + switch (s->metadata.compression) + { + case T4_COMPRESSION_T88: + /* Read the raw image, and send it as is */ + if (read_tiff_raw_image(s) < 0) + return -1; + break; + default: + /* libtiff probably cannot decompress T.88, so we must handle it ourselves */ + /* Decode the whole image into a buffer */ + if (read_tiff_t88_image(s) < 0) + return -1; + break; + } break; +#endif + case COMPRESSION_T85: + switch (s->metadata.compression) + { + case T4_COMPRESSION_T85: + case T4_COMPRESSION_T85_L0: + /* Read the raw image, and send it as is */ + if (read_tiff_raw_image(s) < 0) + return -1; + break; + default: + /* libtiff probably cannot decompress T.85, so we must handle it ourselves */ + /* Decode the whole image into a buffer */ + if (read_tiff_t85_image(s) < 0) + return -1; + break; + } + break; +#if 0 + case COMPRESSION_CCITT_T6: + switch (s->metadata.compression) + { + case T4_COMPRESSION_T6: + /* Read the raw image, and send it as is */ + if (read_tiff_raw_image(s) < 0) + return -1; + break; + default: + /* Decode the whole image into a buffer */ + /* Let libtiff handle the decompression */ + if (read_tiff_decompressed_image(s) < 0) + return -1; + break; + } + break; +#endif default: /* Decode the whole image into a buffer */ /* Let libtiff handle the decompression */ @@ -930,12 +1399,12 @@ static void tiff_tx_release(t4_tx_state_t *s) TIFFClose(s->tiff.tiff_file); s->tiff.tiff_file = NULL; if (s->tiff.file) - free((char *) s->tiff.file); + span_free((char *) s->tiff.file); s->tiff.file = NULL; } if (s->tiff.image_buffer) { - free(s->tiff.image_buffer); + span_free(s->tiff.image_buffer); s->tiff.image_buffer = NULL; s->tiff.image_size = 0; s->tiff.image_buffer_size = 0; @@ -1023,37 +1492,74 @@ static int header_row_read_handler(void *user_data, uint8_t buf[], size_t len) int pattern; int pos; int row; + int i; char *t; t4_tx_state_t *s; s = (t4_tx_state_t *) user_data; - switch (s->metadata.y_resolution) + switch (s->metadata.resolution_code) { - case T4_Y_RESOLUTION_1200: - y_repeats = 12; - break; - case T4_Y_RESOLUTION_800: - y_repeats = 8; - break; - case T4_Y_RESOLUTION_600: - y_repeats = 6; - break; - case T4_Y_RESOLUTION_SUPERFINE: - case T4_Y_RESOLUTION_400: - y_repeats = 4; - break; - case T4_Y_RESOLUTION_300: - y_repeats = 3; - break; - case T4_Y_RESOLUTION_FINE: - case T4_Y_RESOLUTION_200: - y_repeats = 2; - break; default: + case T4_RESOLUTION_100_100: + x_repeats = 1; y_repeats = 1; break; + case T4_RESOLUTION_R8_STANDARD: + case T4_RESOLUTION_200_100: + x_repeats = 2; + y_repeats = 1; + break; + case T4_RESOLUTION_R8_FINE: + case T4_RESOLUTION_200_200: + x_repeats = 2; + y_repeats = 2; + break; + case T4_RESOLUTION_300_300: + x_repeats = 3; + y_repeats = 3; + break; + case T4_RESOLUTION_R8_SUPERFINE: + case T4_RESOLUTION_200_400: + x_repeats = 2; + y_repeats = 4; + break; + case T4_RESOLUTION_R16_SUPERFINE: + case T4_RESOLUTION_400_400: + x_repeats = 4; + y_repeats = 4; + break; + case T4_RESOLUTION_400_800: + x_repeats = 4; + y_repeats = 8; + break; + case T4_RESOLUTION_300_600: + x_repeats = 3; + y_repeats = 6; + break; + case T4_RESOLUTION_600_600: + x_repeats = 6; + y_repeats = 6; + break; + case T4_RESOLUTION_600_1200: + x_repeats = 6; + y_repeats = 12; + break; + case T4_RESOLUTION_1200_1200: + x_repeats = 12; + y_repeats = 12; + break; + } + switch (s->metadata.width_code) + { + case T4_SUPPORT_WIDTH_215MM: + break; + case T4_SUPPORT_WIDTH_255MM: + x_repeats *= 2; + break; + case T4_SUPPORT_WIDTH_303MM: + x_repeats *= 3; + break; } - y_repeats /= s->row_squashing_ratio; if (s->header_overlays_image) { /* Read and dump a row of the real image, allowing for the possibility @@ -1064,16 +1570,60 @@ static int header_row_read_handler(void *user_data, uint8_t buf[], size_t len) return len; } } + t = s->header_text; row = s->header_row/y_repeats; pos = 0; - for (t = s->header_text; *t && pos <= len - 2; t++) + switch (s->metadata.image_type) { - pattern = header_font[(uint8_t) *t][row]; - buf[pos++] = (uint8_t) (pattern >> 8); - buf[pos++] = (uint8_t) (pattern & 0xFF); + case T4_IMAGE_TYPE_BILEVEL: + for ( ; *t && pos <= len - 2; t++) + { + pattern = header_font[(uint8_t) *t][row]; + buf[pos++] = (uint8_t) (pattern >> 8); + buf[pos++] = (uint8_t) (pattern & 0xFF); + } + if (pos < len) + memset(&buf[pos], 0, len - pos); + break; + case T4_IMAGE_TYPE_GRAY_8BIT: + for ( ; *t && pos <= len - 2; t++) + { + pattern = header_font[(uint8_t) *t][row]; + for (i = 0; i < 16; i++) + { + buf[pos + i] = (pattern & 0x8000) ? 0 : 0xFF; + pattern <<= 1; + } + pos += 16; + } + if (pos < len) + memset(&buf[pos], 0xFF, len - pos); + break; + case T4_IMAGE_TYPE_COLOUR_8BIT: + for ( ; *t && pos <= len - 2; t++) + { + pattern = header_font[(uint8_t) *t][row]; + for (i = 0; i < 16; i++) + { + buf[pos + 3*i + 0] = + buf[pos + 3*i + 1] = + buf[pos + 3*i + 2] = (pattern & 0x8000) ? 0 : 0xFF; + pattern <<= 1; + } + pos += 3*16; + } + if (pos < len) + memset(&buf[pos], 0xFF, len - pos); + break; + case T4_IMAGE_TYPE_COLOUR_BILEVEL: + case T4_IMAGE_TYPE_4COLOUR_BILEVEL: + case T4_IMAGE_TYPE_GRAY_12BIT: + case T4_IMAGE_TYPE_4COLOUR_8BIT: + case T4_IMAGE_TYPE_COLOUR_12BIT: + case T4_IMAGE_TYPE_4COLOUR_12BIT: + default: + memset(buf, 0xFF, len); } - while (pos < len) - buf[pos++] = 0; s->header_row++; if (s->header_row >= 16*y_repeats) { @@ -1084,12 +1634,6 @@ static int header_row_read_handler(void *user_data, uint8_t buf[], size_t len) } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(void) t4_tx_set_row_squashing_ratio(t4_tx_state_t *s, int row_squashing_ratio) -{ - s->row_squashing_ratio = row_squashing_ratio; -} -/*- End of function --------------------------------------------------------*/ - SPAN_DECLARE(int) t4_tx_next_page_has_different_format(t4_tx_state_t *s) { span_log(&s->logging, SPAN_LOG_FLOW, "Checking for the existence of page %d\n", s->current_page + 1); @@ -1113,8 +1657,372 @@ SPAN_DECLARE(int) t4_tx_set_row_read_handler(t4_tx_state_t *s, t4_row_read_handl } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(int) t4_tx_set_tx_encoding(t4_tx_state_t *s, int compression) +SPAN_DECLARE(int) t4_tx_set_tx_image_format(t4_tx_state_t *s, + int supported_compressions, + int supported_image_sizes, + int supported_bilevel_resolutions, + int supported_colour_resolutions) { + static const struct + { + int width; + int width_code; + int res_code; /* Correct resolution code */ + int alt_res_code; /* Fallback resolution code, where a metric/inch swap is possible */ + } width_info[] = + { + { T4_WIDTH_100_A4, T4_SUPPORT_WIDTH_215MM, T4_RESOLUTION_100_100, 0}, + { T4_WIDTH_100_B4, T4_SUPPORT_WIDTH_255MM, T4_RESOLUTION_100_100, 0}, + { T4_WIDTH_100_A3, T4_SUPPORT_WIDTH_303MM, T4_RESOLUTION_100_100, 0}, + { T4_WIDTH_200_A4, T4_SUPPORT_WIDTH_215MM, T4_RESOLUTION_200_100, T4_RESOLUTION_R8_STANDARD}, + { T4_WIDTH_200_A4, T4_SUPPORT_WIDTH_215MM, T4_RESOLUTION_200_200, T4_RESOLUTION_R8_FINE}, + { T4_WIDTH_200_A4, T4_SUPPORT_WIDTH_215MM, T4_RESOLUTION_200_400, T4_RESOLUTION_R8_SUPERFINE}, + { T4_WIDTH_200_A4, T4_SUPPORT_WIDTH_215MM, T4_RESOLUTION_R8_STANDARD, T4_RESOLUTION_200_100}, + { T4_WIDTH_200_A4, T4_SUPPORT_WIDTH_215MM, T4_RESOLUTION_R8_FINE, T4_RESOLUTION_200_200}, + { T4_WIDTH_200_A4, T4_SUPPORT_WIDTH_215MM, T4_RESOLUTION_R8_SUPERFINE, T4_RESOLUTION_200_400}, + { T4_WIDTH_200_B4, T4_SUPPORT_WIDTH_255MM, T4_RESOLUTION_200_100, T4_RESOLUTION_R8_STANDARD}, + { T4_WIDTH_200_B4, T4_SUPPORT_WIDTH_255MM, T4_RESOLUTION_200_200, T4_RESOLUTION_R8_FINE}, + { T4_WIDTH_200_B4, T4_SUPPORT_WIDTH_255MM, T4_RESOLUTION_200_400, T4_RESOLUTION_R8_SUPERFINE}, + { T4_WIDTH_200_B4, T4_SUPPORT_WIDTH_255MM, T4_RESOLUTION_R8_STANDARD, T4_RESOLUTION_200_100}, + { T4_WIDTH_200_B4, T4_SUPPORT_WIDTH_255MM, T4_RESOLUTION_R8_FINE, T4_RESOLUTION_200_200}, + { T4_WIDTH_200_B4, T4_SUPPORT_WIDTH_255MM, T4_RESOLUTION_R8_SUPERFINE, T4_RESOLUTION_200_400}, + { T4_WIDTH_200_A3, T4_SUPPORT_WIDTH_303MM, T4_RESOLUTION_200_100, T4_RESOLUTION_R8_STANDARD}, + { T4_WIDTH_200_A3, T4_SUPPORT_WIDTH_303MM, T4_RESOLUTION_200_200, T4_RESOLUTION_R8_FINE}, + { T4_WIDTH_200_A3, T4_SUPPORT_WIDTH_303MM, T4_RESOLUTION_200_400, T4_RESOLUTION_R8_SUPERFINE}, + { T4_WIDTH_200_A3, T4_SUPPORT_WIDTH_303MM, T4_RESOLUTION_R8_STANDARD, T4_RESOLUTION_200_100}, + { T4_WIDTH_200_A3, T4_SUPPORT_WIDTH_303MM, T4_RESOLUTION_R8_FINE, T4_RESOLUTION_200_200}, + { T4_WIDTH_200_A3, T4_SUPPORT_WIDTH_303MM, T4_RESOLUTION_R8_SUPERFINE, T4_RESOLUTION_200_400}, + { T4_WIDTH_300_A4, T4_SUPPORT_WIDTH_215MM, T4_RESOLUTION_300_300, 0}, + { T4_WIDTH_300_A4, T4_SUPPORT_WIDTH_215MM, T4_RESOLUTION_300_600, 0}, + { T4_WIDTH_300_B4, T4_SUPPORT_WIDTH_255MM, T4_RESOLUTION_300_300, 0}, + { T4_WIDTH_300_B4, T4_SUPPORT_WIDTH_255MM, T4_RESOLUTION_300_600, 0}, + { T4_WIDTH_400_A4, T4_SUPPORT_WIDTH_215MM, T4_RESOLUTION_400_400, T4_RESOLUTION_R16_SUPERFINE}, + { T4_WIDTH_400_A4, T4_SUPPORT_WIDTH_215MM, T4_RESOLUTION_400_800, 0}, + { T4_WIDTH_400_A4, T4_SUPPORT_WIDTH_215MM, T4_RESOLUTION_R16_SUPERFINE, T4_RESOLUTION_400_400}, + { T4_WIDTH_300_A3, T4_SUPPORT_WIDTH_303MM, T4_RESOLUTION_300_300, 0}, + { T4_WIDTH_300_A3, T4_SUPPORT_WIDTH_303MM, T4_RESOLUTION_300_600, 0}, + { T4_WIDTH_400_B4, T4_SUPPORT_WIDTH_255MM, T4_RESOLUTION_400_400, T4_RESOLUTION_R16_SUPERFINE}, + { T4_WIDTH_400_B4, T4_SUPPORT_WIDTH_255MM, T4_RESOLUTION_400_800, 0}, + { T4_WIDTH_400_B4, T4_SUPPORT_WIDTH_255MM, T4_RESOLUTION_R16_SUPERFINE, T4_RESOLUTION_400_400}, + { T4_WIDTH_400_A3, T4_SUPPORT_WIDTH_303MM, T4_RESOLUTION_400_400, T4_RESOLUTION_R16_SUPERFINE}, + { T4_WIDTH_400_A3, T4_SUPPORT_WIDTH_303MM, T4_RESOLUTION_400_800, 0}, + { T4_WIDTH_400_A3, T4_SUPPORT_WIDTH_303MM, T4_RESOLUTION_R16_SUPERFINE, T4_RESOLUTION_400_400}, + { T4_WIDTH_600_A4, T4_SUPPORT_WIDTH_215MM, T4_RESOLUTION_600_600, 0}, + { T4_WIDTH_600_A4, T4_SUPPORT_WIDTH_215MM, T4_RESOLUTION_600_1200, 0}, + { T4_WIDTH_600_B4, T4_SUPPORT_WIDTH_255MM, T4_RESOLUTION_600_600, 0}, + { T4_WIDTH_600_B4, T4_SUPPORT_WIDTH_255MM, T4_RESOLUTION_600_1200, 0}, + { T4_WIDTH_600_A3, T4_SUPPORT_WIDTH_303MM, T4_RESOLUTION_600_600, 0}, + { T4_WIDTH_600_A3, T4_SUPPORT_WIDTH_303MM, T4_RESOLUTION_600_1200, 0}, + {T4_WIDTH_1200_A4, T4_SUPPORT_WIDTH_215MM, T4_RESOLUTION_1200_1200, 0}, + {T4_WIDTH_1200_B4, T4_SUPPORT_WIDTH_255MM, T4_RESOLUTION_1200_1200, 0}, + {T4_WIDTH_1200_A3, T4_SUPPORT_WIDTH_303MM, T4_RESOLUTION_1200_1200, 0}, + {0x7FFFFFFF, -1, -1, -1} + }; + + static const struct + { + int resolution; + struct + { + int resolution; + int squashing_factor; + } fallback[4]; + } squashable[4] = + { + { + T4_RESOLUTION_200_400, + { + {T4_RESOLUTION_200_200, 2}, + {T4_RESOLUTION_R8_FINE, 2}, + {T4_RESOLUTION_200_100, 4}, + {T4_RESOLUTION_R8_STANDARD, 4} + } + }, + { + T4_RESOLUTION_200_200, + { + {T4_RESOLUTION_200_100, 2}, + {T4_RESOLUTION_R8_STANDARD, 2}, + {0, 0}, + {0, 0} + } + }, + { + T4_RESOLUTION_R8_SUPERFINE, + { + {T4_RESOLUTION_R8_FINE, 2}, + {T4_RESOLUTION_200_200, 2}, + {T4_RESOLUTION_R8_STANDARD, 4}, + {T4_RESOLUTION_200_100, 4} + } + }, + { + T4_RESOLUTION_R8_FINE, + { + {T4_RESOLUTION_R8_STANDARD, 2}, + {T4_RESOLUTION_200_100, 2}, + {0, 0}, + {0, 0} + } + } + }; + + int i; + int j; + int entry; + int compression; + int res; + + compression = -1; + s->metadata.image_type = s->tiff.image_type; + if (s->tiff.image_type != T4_IMAGE_TYPE_BILEVEL) + { + span_log(&s->logging, SPAN_LOG_FLOW, "Non-bi-level image\n"); + /* Can we send this page as it is? */ + if (supported_colour_resolutions + && + (supported_compressions & (T4_COMPRESSION_T42_T81 | T4_COMPRESSION_T43 | T4_COMPRESSION_T45 | T4_COMPRESSION_SYCC_T81)) + && + (((s->tiff.image_type == T4_IMAGE_TYPE_COLOUR_BILEVEL || s->tiff.image_type == T4_IMAGE_TYPE_COLOUR_8BIT || s->tiff.image_type == T4_IMAGE_TYPE_COLOUR_12BIT) + && + (supported_compressions & T4_COMPRESSION_COLOUR)) + || + ((s->tiff.image_type == T4_IMAGE_TYPE_GRAY_8BIT || s->tiff.image_type == T4_IMAGE_TYPE_GRAY_12BIT) + && + (supported_compressions & T4_COMPRESSION_GRAYSCALE)))) + { + /* Gray-scale/colour is possible */ + span_log(&s->logging, SPAN_LOG_FLOW, "Gray-scale/colour is allowed\n"); + if (s->tiff.image_type == T4_IMAGE_TYPE_COLOUR_BILEVEL + || + s->tiff.image_type == T4_IMAGE_TYPE_COLOUR_8BIT + || + s->tiff.image_type == T4_IMAGE_TYPE_COLOUR_12BIT) + { + if (!(supported_compressions & T4_COMPRESSION_COLOUR)) + { + span_log(&s->logging, SPAN_LOG_FLOW, "Colour is not allowed\n"); + return T4_IMAGE_FORMAT_INCOMPATIBLE; + } + } + else if (s->tiff.image_type == T4_IMAGE_TYPE_GRAY_8BIT + || + s->tiff.image_type == T4_IMAGE_TYPE_GRAY_12BIT) + { + if (!(supported_compressions & T4_COMPRESSION_GRAYSCALE)) + { + span_log(&s->logging, SPAN_LOG_FLOW, "Gray-scale is not allowed\n"); + return T4_IMAGE_FORMAT_INCOMPATIBLE; + } + } + /* Choose the best gray-scale/colour encoding available to us */ + if (s->tiff.image_type == T4_IMAGE_TYPE_COLOUR_BILEVEL && (supported_compressions & T4_COMPRESSION_T43)) + compression = T4_COMPRESSION_T43; + else if ((supported_compressions & T4_COMPRESSION_T42_T81)) + compression = T4_COMPRESSION_T42_T81; + else if ((supported_compressions & T4_COMPRESSION_T43)) + compression = T4_COMPRESSION_T43; + else if ((supported_compressions & T4_COMPRESSION_T45)) + compression = T4_COMPRESSION_T45; + else if ((supported_compressions & T4_COMPRESSION_SYCC_T81)) + compression = T4_COMPRESSION_SYCC_T81; + + //best_colour_resolution(s->tiff.x_resolution, supported_colour_resolutions); + } + else + { + /* Gray-scale/colour is not possible. Can we flatten the image to send it? */ + span_log(&s->logging, SPAN_LOG_FLOW, "Gray-scale/colour is not allowed\n"); + if (s->tiff.image_type == T4_IMAGE_TYPE_COLOUR_BILEVEL + || + s->tiff.image_type == T4_IMAGE_TYPE_COLOUR_8BIT + || + s->tiff.image_type == T4_IMAGE_TYPE_COLOUR_12BIT) + { + if (!(supported_compressions & T4_COMPRESSION_COLOUR_TO_BILEVEL)) + { + span_log(&s->logging, SPAN_LOG_FLOW, "Flattening is not allowed\n"); + return T4_IMAGE_FORMAT_INCOMPATIBLE; + } + s->metadata.image_type = T4_IMAGE_TYPE_BILEVEL; + } + else if (s->tiff.image_type == T4_IMAGE_TYPE_GRAY_8BIT + || + s->tiff.image_type == T4_IMAGE_TYPE_GRAY_12BIT) + { + if (!(supported_compressions & T4_COMPRESSION_GRAY_TO_BILEVEL)) + { + span_log(&s->logging, SPAN_LOG_FLOW, "Flattening is not allowed\n"); + return T4_IMAGE_FORMAT_INCOMPATIBLE; + } + s->metadata.image_type = T4_IMAGE_TYPE_BILEVEL; + } + /* Squashing to a bi-level image is possible */ + span_log(&s->logging, SPAN_LOG_FLOW, "The image may be flattened to %d\n", s->metadata.image_type); + } + } + + if (s->metadata.image_type == T4_IMAGE_TYPE_BILEVEL) + { + /* Choose the best bi-level encoding available to us */ + if ((supported_compressions & T4_COMPRESSION_T85_L0)) + compression = T4_COMPRESSION_T85_L0; + else if ((supported_compressions & T4_COMPRESSION_T85)) + compression = T4_COMPRESSION_T85; + else if ((supported_compressions & T4_COMPRESSION_T6)) + compression = T4_COMPRESSION_T6; + else if ((supported_compressions & T4_COMPRESSION_T4_2D)) + compression = T4_COMPRESSION_T4_2D; + else + compression = T4_COMPRESSION_T4_1D; + } + + /* Deal with the image width/resolution combination. */ + /* Look for a pattern that matches the image */ + res = T4_IMAGE_FORMAT_NOSIZESUPPORT; + for (entry = 0; s->tiff.image_width >= width_info[entry].width; entry++) + { + if (s->tiff.image_width == width_info[entry].width && s->tiff.resolution_code == width_info[entry].res_code) + { + res = T4_IMAGE_FORMAT_OK; + break; + } + } + + s->metadata.width_code = width_info[entry].width_code; + + s->row_squashing_ratio = 1; + if (res == T4_IMAGE_FORMAT_OK) + { + /* We have a valid width/resolution combination */ + + /* Check if this width/resolution combination is supported */ + if (!(supported_image_sizes & width_info[entry].width_code)) + return T4_IMAGE_FORMAT_NOSIZESUPPORT; + + /* No resize necessary */ + s->metadata.image_width = s->tiff.image_width; + s->metadata.image_length = s->tiff.image_length; + + res = T4_IMAGE_FORMAT_NORESSUPPORT; + if (s->metadata.image_type == T4_IMAGE_TYPE_BILEVEL) + { + if ((width_info[entry].res_code & supported_bilevel_resolutions)) + { + /* We can use the resolution of the original image */ + s->metadata.resolution_code = s->tiff.resolution_code; + s->metadata.x_resolution = code_to_x_resolution(s->metadata.resolution_code); + s->metadata.y_resolution = code_to_y_resolution(s->metadata.resolution_code); + res = T4_IMAGE_FORMAT_OK; + } + else + { + /* The resolution is not supported, but there might be an approximation, or a length + squashing that might work. */ + if ((width_info[entry].alt_res_code & supported_bilevel_resolutions)) + { + /* We can do a metric/imperial swap, and have a usable resolution */ + span_log(&s->logging, + SPAN_LOG_FLOW, + "Image resolution %s falls back to %s\n", + t4_image_resolution_to_str(s->tiff.resolution_code), + t4_image_resolution_to_str(width_info[entry].alt_res_code)); + s->metadata.resolution_code = width_info[entry].alt_res_code; + s->metadata.x_resolution = code_to_x_resolution(s->metadata.resolution_code); + s->metadata.y_resolution = code_to_y_resolution(s->metadata.resolution_code); + res = T4_IMAGE_FORMAT_OK; + } + else + { + if (s->tiff.image_type == T4_IMAGE_TYPE_BILEVEL) + { + if ((s->tiff.resolution_code & (T4_RESOLUTION_200_400 | T4_RESOLUTION_200_200 | T4_RESOLUTION_R8_SUPERFINE | T4_RESOLUTION_R8_FINE))) + { + /* This might be a resolution we can squash down to something which is supported */ + for (i = 0; i < 4; i++) + { + if ((s->tiff.resolution_code & squashable[i].resolution)) + break; + } + if (i < 4) + { + /* This is a squashable resolution, so let's see if there is a valid + fallback we can squash the image to, scanning through the entries + in their order of preference. */ + for (j = 0; j < 4; j++) + { + if ((supported_bilevel_resolutions & squashable[i].fallback[j].resolution)) + { + span_log(&s->logging, + SPAN_LOG_FLOW, + "Image resolution %s falls back to %s\n", + t4_image_resolution_to_str(s->tiff.resolution_code), + t4_image_resolution_to_str(squashable[i].fallback[j].resolution)); + s->row_squashing_ratio = squashable[i].fallback[j].squashing_factor; + s->metadata.resolution_code = squashable[i].fallback[j].resolution; + s->metadata.x_resolution = code_to_x_resolution(s->metadata.resolution_code); + s->metadata.y_resolution = code_to_y_resolution(s->metadata.resolution_code); + res = T4_IMAGE_FORMAT_OK; + break; + } + } + } + } + } + } + } + /* If we have not succeeded in matching up the size and resolution, the next step will + depend on whether the original was a bi-level image. If it was we are stuck, as you can't + really resize those. If it was not, a resize might be possible */ + if (res != T4_IMAGE_FORMAT_OK) + { + if (s->tiff.image_type == T4_IMAGE_TYPE_BILEVEL) + return T4_IMAGE_FORMAT_NORESSUPPORT; + if (!(supported_compressions & T4_COMPRESSION_RESCALING)) + return T4_IMAGE_FORMAT_NORESSUPPORT; + } + /* TODO */ + } + else + { + if ((width_info[entry].res_code & supported_bilevel_resolutions)) + { + if ((s->tiff.resolution_code & supported_colour_resolutions)) + { + /* We can use the resolution of the original image */ + s->metadata.resolution_code = width_info[entry].res_code; + s->metadata.x_resolution = code_to_x_resolution(s->metadata.resolution_code); + s->metadata.y_resolution = code_to_y_resolution(s->metadata.resolution_code); + res = T4_IMAGE_FORMAT_OK; + } + } + } + } + else + { + /* Can we rework the image to fit? */ + /* We can't rework a bilevel image that fits none of the patterns */ + if (s->tiff.image_type == T4_IMAGE_TYPE_BILEVEL) + return T4_IMAGE_FORMAT_NORESSUPPORT; + res = T4_IMAGE_FORMAT_OK; + /* Any other kind of image might be resizable */ + s->metadata.image_width = T4_WIDTH_200_A4; + s->metadata.resolution_code = T4_RESOLUTION_200_200; + s->metadata.x_resolution = code_to_x_resolution(s->metadata.resolution_code); + s->metadata.y_resolution = code_to_y_resolution(s->metadata.resolution_code); + } + + if (res != T4_IMAGE_FORMAT_OK) + return res; + + if (s->metadata.image_type != s->tiff.image_type || s->metadata.image_width != s->tiff.image_width) + { + if (image_translate_init(&s->translator, s->metadata.image_type, s->metadata.image_width, -1, s->tiff.image_type, s->tiff.image_width, s->tiff.image_length, translate_row_read2, s) == NULL) + return T4_IMAGE_FORMAT_INCOMPATIBLE; + s->metadata.image_length = image_translate_get_output_length(&s->translator); + } + + if (compression != s->metadata.compression) { switch (compression) { @@ -1129,13 +2037,13 @@ SPAN_DECLARE(int) t4_tx_set_tx_encoding(t4_tx_state_t *s, int compression) break; default: t4_t6_encode_init(&s->encoder.t4_t6, compression, s->metadata.image_width, s->metadata.image_length, s->row_handler, s->row_handler_user_data); - t4_t6_encode_set_max_2d_rows_per_1d_row(&s->encoder.t4_t6, -s->metadata.y_resolution); break; } s->metadata.compression = compression; + res = T4_IMAGE_FORMAT_OK; if (t4_t6_encode_set_encoding(&s->encoder.t4_t6, compression)) - return -1; - return s->metadata.compression; + res = -1; + break; case T4_COMPRESSION_T85: case T4_COMPRESSION_T85_L0: switch (s->metadata.compression) @@ -1148,7 +2056,8 @@ SPAN_DECLARE(int) t4_tx_set_tx_encoding(t4_tx_state_t *s, int compression) break; } s->metadata.compression = compression; - return s->metadata.compression; + res = T4_IMAGE_FORMAT_OK; + break; #if defined(SPANDSP_SUPPORT_T88) case T4_COMPRESSION_T88: switch (s->metadata.compression) @@ -1160,7 +2069,8 @@ SPAN_DECLARE(int) t4_tx_set_tx_encoding(t4_tx_state_t *s, int compression) break; } s->metadata.compression = compression; - return s->metadata.compression; + res = T4_IMAGE_FORMAT_OK; + break; #endif case T4_COMPRESSION_T42_T81: case T4_COMPRESSION_SYCC_T81: @@ -1174,7 +2084,8 @@ SPAN_DECLARE(int) t4_tx_set_tx_encoding(t4_tx_state_t *s, int compression) break; } s->metadata.compression = compression; - return s->metadata.compression; + res = T4_IMAGE_FORMAT_OK; + break; #if defined(SPANDSP_SUPPORT_T43) case T4_COMPRESSION_T43: switch (s->metadata.compression) @@ -1186,7 +2097,8 @@ SPAN_DECLARE(int) t4_tx_set_tx_encoding(t4_tx_state_t *s, int compression) break; } s->metadata.compression = compression; - return s->metadata.compression; + res = T4_IMAGE_FORMAT_OK; + break; #endif #if defined(SPANDSP_SUPPORT_T45) case T4_COMPRESSION_T45: @@ -1199,24 +2111,25 @@ SPAN_DECLARE(int) t4_tx_set_tx_encoding(t4_tx_state_t *s, int compression) break; } s->metadata.compression = compression; - return s->metadata.compression; + res = T4_IMAGE_FORMAT_OK; + break; #endif } } - return -1; -} -/*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(void) t4_tx_set_min_bits_per_row(t4_tx_state_t *s, int bits) -{ switch (s->metadata.compression) { case T4_COMPRESSION_T4_1D: case T4_COMPRESSION_T4_2D: case T4_COMPRESSION_T6: - t4_t6_encode_set_min_bits_per_row(&s->encoder.t4_t6, bits); + t4_t6_encode_set_max_2d_rows_per_1d_row(&s->encoder.t4_t6, -s->metadata.y_resolution); break; } + + set_image_width(s, s->metadata.image_width); + set_image_length(s, s->metadata.image_length); + t4_tx_set_image_type(s, s->metadata.image_type); + return res; } /*- End of function --------------------------------------------------------*/ @@ -1256,7 +2169,13 @@ SPAN_DECLARE(int) t4_tx_get_tx_image_width(t4_tx_state_t *s) } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(void) t4_tx_set_image_width(t4_tx_state_t *s, int image_width) +SPAN_DECLARE(int) t4_tx_get_tx_image_width_code(t4_tx_state_t *s) +{ + return s->metadata.width_code; +} +/*- End of function --------------------------------------------------------*/ + +static void set_image_width(t4_tx_state_t *s, uint32_t image_width) { s->metadata.image_width = image_width; switch (s->metadata.compression) @@ -1293,11 +2212,16 @@ SPAN_DECLARE(void) t4_tx_set_image_width(t4_tx_state_t *s, int image_width) } /*- End of function --------------------------------------------------------*/ -static void t4_tx_set_image_length(t4_tx_state_t *s, uint32_t image_length) +static void set_image_length(t4_tx_state_t *s, uint32_t image_length) { s->metadata.image_length = image_length; switch (s->metadata.compression) { + case T4_COMPRESSION_T4_1D: + case T4_COMPRESSION_T4_2D: + case T4_COMPRESSION_T6: + t4_t6_encode_set_image_length(&s->encoder.t4_t6, image_length); + break; case T4_COMPRESSION_T85: case T4_COMPRESSION_T85_L0: t85_encode_set_image_length(&s->encoder.t85, image_length); @@ -1325,6 +2249,47 @@ static void t4_tx_set_image_length(t4_tx_state_t *s, uint32_t image_length) } /*- End of function --------------------------------------------------------*/ +static void t4_tx_set_image_type(t4_tx_state_t *s, int image_type) +{ + s->metadata.image_type = image_type; + switch (s->metadata.compression) + { +#if defined(SPANDSP_SUPPORT_T88) + case T4_COMPRESSION_T88: + t88_encode_set_image_type(&s->encoder.t88, image_type); + break; +#endif + case T4_COMPRESSION_T42_T81: + case T4_COMPRESSION_SYCC_T81: + t42_encode_set_image_type(&s->encoder.t42, image_type); + break; +#if defined(SPANDSP_SUPPORT_T43) + case T4_COMPRESSION_T43: + t43_encode_set_image_type(&s->encoder.t43, image_type); + break; +#endif +#if defined(SPANDSP_SUPPORT_T45) + case T4_COMPRESSION_T45: + t45_encode_set_image_type(&s->encoder.t45, image_type); + break; +#endif + } +} +/*- End of function --------------------------------------------------------*/ + +SPAN_DECLARE(void) t4_tx_set_min_bits_per_row(t4_tx_state_t *s, int bits) +{ + switch (s->metadata.compression) + { + case T4_COMPRESSION_T4_1D: + case T4_COMPRESSION_T4_2D: + case T4_COMPRESSION_T6: + t4_t6_encode_set_min_bits_per_row(&s->encoder.t4_t6, bits); + break; + } +} +/*- End of function --------------------------------------------------------*/ + SPAN_DECLARE(void) t4_tx_set_max_2d_rows_per_1d_row(t4_tx_state_t *s, int max) { switch (s->metadata.compression) @@ -1395,8 +2360,9 @@ SPAN_DECLARE(void) t4_tx_get_transfer_statistics(t4_tx_state_t *s, t4_stats_t *t t->image_x_resolution = s->tiff.x_resolution; t->image_y_resolution = s->tiff.y_resolution; t->x_resolution = s->metadata.x_resolution; - t->y_resolution = s->metadata.y_resolution/s->row_squashing_ratio; + t->y_resolution = s->metadata.y_resolution; + t->type = s->metadata.image_type; t->compression = s->metadata.compression; switch (s->metadata.compression) @@ -1404,16 +2370,14 @@ SPAN_DECLARE(void) t4_tx_get_transfer_statistics(t4_tx_state_t *s, t4_stats_t *t case T4_COMPRESSION_T4_1D: case T4_COMPRESSION_T4_2D: case T4_COMPRESSION_T6: - t->type = T4_IMAGE_TYPE_BILEVEL; t->width = t4_t6_encode_get_image_width(&s->encoder.t4_t6); - t->length = t4_t6_encode_get_image_length(&s->encoder.t4_t6)/s->row_squashing_ratio; + t->length = t4_t6_encode_get_image_length(&s->encoder.t4_t6); t->line_image_size = t4_t6_encode_get_compressed_image_size(&s->encoder.t4_t6)/8; break; case T4_COMPRESSION_T85: case T4_COMPRESSION_T85_L0: - t->type = T4_IMAGE_TYPE_BILEVEL; t->width = t85_encode_get_image_width(&s->encoder.t85); - t->length = t85_encode_get_image_length(&s->encoder.t85)/s->row_squashing_ratio; + t->length = t85_encode_get_image_length(&s->encoder.t85); t->line_image_size = t85_encode_get_compressed_image_size(&s->encoder.t85)/8; break; #if defined(SPANDSP_SUPPORT_T88) @@ -1425,16 +2389,14 @@ SPAN_DECLARE(void) t4_tx_get_transfer_statistics(t4_tx_state_t *s, t4_stats_t *t #endif case T4_COMPRESSION_T42_T81: case T4_COMPRESSION_SYCC_T81: - t->type = 0; t->width = t42_encode_get_image_width(&s->encoder.t42); - t->length = t42_encode_get_image_length(&s->encoder.t42)/s->row_squashing_ratio; + t->length = t42_encode_get_image_length(&s->encoder.t42); t->line_image_size = t42_encode_get_compressed_image_size(&s->encoder.t42)/8; break; #if defined(SPANDSP_SUPPORT_T43) case T4_COMPRESSION_T43: - t->type = 0; t->width = t43_encode_get_image_width(&s->encoder.t43); - t->length = t43_encode_get_image_length(&s->encoder.t43)/s->row_squashing_ratio; + t->length = t43_encode_get_image_length(&s->encoder.t43); t->line_image_size = t43_encode_get_compressed_image_size(&s->encoder.t43)/8; break; #endif @@ -1451,6 +2413,13 @@ SPAN_DECLARE(void) t4_tx_get_transfer_statistics(t4_tx_state_t *s, t4_stats_t *t SPAN_DECLARE(int) t4_tx_image_complete(t4_tx_state_t *s) { + if (s->pre_encoded_len > 0) + { + if (s->pre_encoded_ptr >= s->pre_encoded_len) + return SIG_STATUS_END_OF_DATA; + return 0; + } + switch (s->metadata.compression) { case T4_COMPRESSION_T4_1D: @@ -1482,7 +2451,21 @@ SPAN_DECLARE(int) t4_tx_image_complete(t4_tx_state_t *s) SPAN_DECLARE(int) t4_tx_get_bit(t4_tx_state_t *s) { + int bit; + /* We only get bit by bit for T.4 1D and T.4 2-D. */ + if (s->pre_encoded_len > 0) + { + if (s->pre_encoded_ptr >= s->pre_encoded_len) + return SIG_STATUS_END_OF_DATA; + bit = (s->pre_encoded_buf[s->pre_encoded_ptr] >> s->pre_encoded_bit) & 1; + if (++s->pre_encoded_bit >= 8) + { + s->pre_encoded_bit = 0; + s->pre_encoded_ptr++; + } + return bit; + } return t4_t6_encode_get_bit(&s->encoder.t4_t6); } /*- End of function --------------------------------------------------------*/ @@ -1500,6 +2483,7 @@ SPAN_DECLARE(int) t4_tx_get(t4_tx_state_t *s, uint8_t buf[], size_t max_len) if (s->image_get_handler) return s->image_get_handler((void *) &s->encoder, buf, max_len); + return 0; } /*- End of function --------------------------------------------------------*/ @@ -1562,9 +2546,10 @@ SPAN_DECLARE(int) t4_tx_start_page(t4_tx_state_t *s) s->image_get_handler = NULL; break; } + /* If there is a page header, create that first */ - if (s->metadata.image_type == T4_IMAGE_TYPE_BILEVEL && s->header_info && s->header_info[0] && make_header(s) == 0) - //if (s->header_info && s->header_info[0] && make_header(s) == 0) + //if (s->metadata.image_type == T4_IMAGE_TYPE_BILEVEL && s->header_info && s->header_info[0] && make_header(s) == 0) + if (s->header_info && s->header_info[0] && make_header(s) == 0) { s->header_row = 0; set_row_read_handler(s, header_row_read_handler, (void *) s); @@ -1633,7 +2618,7 @@ SPAN_DECLARE(t4_tx_state_t *) t4_tx_init(t4_tx_state_t *s, const char *file, int if (open_tiff_input_file(s, file) < 0) { if (allocated) - free(s); + span_free(s); return NULL; } s->tiff.file = strdup(file); @@ -1644,7 +2629,7 @@ SPAN_DECLARE(t4_tx_state_t *) t4_tx_init(t4_tx_state_t *s, const char *file, int { tiff_tx_release(s); if (allocated) - free(s); + span_free(s); return NULL; } } @@ -1658,12 +2643,12 @@ SPAN_DECLARE(int) t4_tx_release(t4_tx_state_t *s) tiff_tx_release(s); if (s->header_text) { - free(s->header_text); + span_free(s->header_text); s->header_text = NULL; } if (s->colour_map) { - free(s->colour_map); + span_free(s->colour_map); s->colour_map = NULL; } switch (s->metadata.compression) @@ -1700,7 +2685,7 @@ SPAN_DECLARE(int) t4_tx_free(t4_tx_state_t *s) int ret; ret = t4_tx_release(s); - free(s); + span_free(s); return ret; } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/tests/Makefile.am b/libs/spandsp/tests/Makefile.am index 8eda2bb201..881a4839b5 100644 --- a/libs/spandsp/tests/Makefile.am +++ b/libs/spandsp/tests/Makefile.am @@ -46,7 +46,7 @@ EXTRA_DIST = fax_tests.sh \ MAINTAINERCLEANFILES = Makefile.in -INCLUDES = -I$(top_builddir)/src -I$(top_builddir)/spandsp-sim -DDATADIR="\"$(pkgdatadir)\"" +AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_builddir)/spandsp-sim -DDATADIR="\"$(pkgdatadir)\"" LIBDIR = -L$(top_builddir)/src diff --git a/libs/spandsp/tests/regression_tests.sh b/libs/spandsp/tests/regression_tests.sh index 31aeb5a952..949eca3fcf 100755 --- a/libs/spandsp/tests/regression_tests.sh +++ b/libs/spandsp/tests/regression_tests.sh @@ -43,6 +43,15 @@ then fi echo adsi_tests completed OK +./alloc_tests >$STDOUT_DEST 2>$STDERR_DEST +RETVAL=$? +if [ $RETVAL != 0 ] +then + echo alloc_tests failed! + exit $RETVAL +fi +echo alloc_tests completed OK + ./async_tests >$STDOUT_DEST 2>$STDERR_DEST RETVAL=$? if [ $RETVAL != 0 ] diff --git a/libs/spandsp/tests/t31_tests.c b/libs/spandsp/tests/t31_tests.c index a002aa73bc..c7d941384f 100644 --- a/libs/spandsp/tests/t31_tests.c +++ b/libs/spandsp/tests/t31_tests.c @@ -106,9 +106,9 @@ static const struct command_response_s fax_send_test_seq[] = EXCHANGE("AT+FRH=3\r", "\r\nCONNECT\r\n"), // #if 1 - RESPONSE("\xFF\x13\x80\x00\xEE\xF8\x80\x80\x89\x80\x80\x80\x18\x18\xB9\x10\x03"), // For audio FAXing + RESPONSE("\xFF\x13\x80\x00\xEE\xF8\x80\x80\x99\x80\x80\x80\x18\x58\x0D\x10\x03"), // For audio FAXing #else - RESPONSE("\xFF\x13\x80\x04\xEE\xF8\x80\x80\x89\x80\x80\x80\x18\x84\x09\x10\x03"), // For T.38 FAXing + RESPONSE("\xFF\x13\x80\x04\xEE\xF8\x80\x80\x99\x80\x80\x80\x18\xC4\xBD\x10\x03"), // For T.38 FAXing #endif RESPONSE("\r\nOK\r\n"), //EXCHANGE("AT+FRH=3\r", "\r\nNO CARRIER\r\n"), diff --git a/libs/spandsp/tests/t4_tests.c b/libs/spandsp/tests/t4_tests.c index ac682bd620..f01b1d3db7 100644 --- a/libs/spandsp/tests/t4_tests.c +++ b/libs/spandsp/tests/t4_tests.c @@ -518,7 +518,6 @@ int main(int argc, char *argv[]) compression = compression_sequence[compression_step++]; } } -#if 0 if (t4_tx_set_tx_image_format(send_state, compression, T4_SUPPORT_WIDTH_215MM @@ -548,8 +547,6 @@ int main(int argc, char *argv[]) { break; } -#endif - t4_tx_set_tx_encoding(send_state, compression); t4_rx_set_rx_encoding(receive_state, compression); if (t4_tx_start_page(send_state)) diff --git a/libs/spandsp/tests/tsb85_tests.c b/libs/spandsp/tests/tsb85_tests.c index d8f626520c..e8064b3d45 100644 --- a/libs/spandsp/tests/tsb85_tests.c +++ b/libs/spandsp/tests/tsb85_tests.c @@ -397,6 +397,7 @@ static void fax_prepare(void) | T4_RESOLUTION_R8_FINE | T4_RESOLUTION_R8_SUPERFINE | T4_RESOLUTION_R16_SUPERFINE + | T4_RESOLUTION_100_100 | T4_RESOLUTION_200_100 | T4_RESOLUTION_200_200 | T4_RESOLUTION_200_400 @@ -980,7 +981,37 @@ static int next_step(faxtester_state_t *s) else if (strcasecmp((const char *) compression, "T.6") == 0) compression_type = T4_COMPRESSION_T6; } - t4_tx_set_tx_encoding(&t4_tx_state, compression_type); + if (t4_tx_set_tx_image_format(&t4_tx_state, + compression_type, + T4_SUPPORT_WIDTH_215MM + | T4_SUPPORT_LENGTH_US_LETTER + | T4_SUPPORT_LENGTH_US_LEGAL + | T4_SUPPORT_LENGTH_UNLIMITED, + T4_RESOLUTION_R8_STANDARD + | T4_RESOLUTION_R8_FINE + | T4_RESOLUTION_R8_SUPERFINE + | T4_RESOLUTION_R16_SUPERFINE + | T4_RESOLUTION_200_100 + | T4_RESOLUTION_200_200 + | T4_RESOLUTION_200_400 + | T4_RESOLUTION_300_300 + | T4_RESOLUTION_300_600 + | T4_RESOLUTION_400_400 + | T4_RESOLUTION_400_800 + | T4_RESOLUTION_600_600 + | T4_RESOLUTION_600_1200 + | T4_RESOLUTION_1200_1200, + T4_RESOLUTION_100_100 + | T4_RESOLUTION_200_200 + | T4_RESOLUTION_300_300 + | T4_RESOLUTION_400_400 + | T4_RESOLUTION_600_600 + | T4_RESOLUTION_1200_1200) < 0) + { + span_log(&s->logging, SPAN_LOG_FLOW, "Failed to set T.4 compression\n"); + printf("Test failed\n"); + exit(2); + } t4_tx_set_min_bits_per_row(&t4_tx_state, min_row_bits); if (t4_tx_start_page(&t4_tx_state)) { @@ -1020,7 +1051,37 @@ static int next_step(faxtester_state_t *s) else if (strcasecmp((const char *) compression, "T.6") == 0) compression_type = T4_COMPRESSION_T6; } - t4_tx_set_tx_encoding(&t4_tx_state, compression_type); + if (t4_tx_set_tx_image_format(&t4_tx_state, + compression_type, + T4_SUPPORT_WIDTH_215MM + | T4_SUPPORT_LENGTH_US_LETTER + | T4_SUPPORT_LENGTH_US_LEGAL + | T4_SUPPORT_LENGTH_UNLIMITED, + T4_RESOLUTION_R8_STANDARD + | T4_RESOLUTION_R8_FINE + | T4_RESOLUTION_R8_SUPERFINE + | T4_RESOLUTION_R16_SUPERFINE + | T4_RESOLUTION_200_100 + | T4_RESOLUTION_200_200 + | T4_RESOLUTION_200_400 + | T4_RESOLUTION_300_300 + | T4_RESOLUTION_300_600 + | T4_RESOLUTION_400_400 + | T4_RESOLUTION_400_800 + | T4_RESOLUTION_600_600 + | T4_RESOLUTION_600_1200 + | T4_RESOLUTION_1200_1200, + T4_RESOLUTION_100_100 + | T4_RESOLUTION_200_200 + | T4_RESOLUTION_300_300 + | T4_RESOLUTION_400_400 + | T4_RESOLUTION_600_600 + | T4_RESOLUTION_1200_1200) < 0) + { + span_log(&s->logging, SPAN_LOG_FLOW, "Failed to set T.4 compression\n"); + printf("Test failed\n"); + exit(2); + } t4_tx_set_min_bits_per_row(&t4_tx_state, min_row_bits); if (t4_tx_start_page(&t4_tx_state)) { From f53bde459ba71aa2552459055d5efc8d17d49874 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 5 Aug 2013 23:49:59 +0500 Subject: [PATCH 07/39] add new file --- Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.am b/Makefile.am index 145733e636..91d949b359 100644 --- a/Makefile.am +++ b/Makefile.am @@ -291,6 +291,7 @@ libfreeswitch_la_SOURCES = \ libs/libnatpmp/natpmp.c \ libs/libnatpmp/getgateway.c\ libs/spandsp/src/plc.c \ + libs/spandsp/src/alloc.c \ libs/spandsp/src/bit_operations.c if ENABLE_CPP From 9ad14d1d3304385096a7a99dcefa1dd18db2a1dd Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Tue, 6 Aug 2013 11:03:01 -0300 Subject: [PATCH 08/39] mod_rayo: Commands executed against a dead call should return item-not-found --- src/mod/event_handlers/mod_rayo/mod_rayo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/event_handlers/mod_rayo/mod_rayo.c b/src/mod/event_handlers/mod_rayo/mod_rayo.c index a110cdb703..7baaf5f46f 100644 --- a/src/mod/event_handlers/mod_rayo/mod_rayo.c +++ b/src/mod/event_handlers/mod_rayo/mod_rayo.c @@ -1424,7 +1424,7 @@ void rayo_call_send(struct rayo_actor *call, struct rayo_message *msg) if (!session) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, session not found\n", RAYO_JID(call)); if (!msg->is_reply) { - RAYO_SEND_REPLY(call, msg->from_jid, iks_new_error(iq, STANZA_ERROR_SERVICE_UNAVAILABLE)); + RAYO_SEND_REPLY(call, msg->from_jid, iks_new_error(iq, STANZA_ERROR_ITEM_NOT_FOUND)); } return; } From 25b068714d4259c0f5540f956dc0c82d35668192 Mon Sep 17 00:00:00 2001 From: Chris Rienzo Date: Tue, 6 Aug 2013 11:05:35 -0400 Subject: [PATCH 09/39] FS-5669 --resolve mod_rayo: return error if is missing in --- src/mod/event_handlers/mod_rayo/mod_rayo.c | 3 ++- .../mod_rayo/rayo_output_component.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/mod/event_handlers/mod_rayo/mod_rayo.c b/src/mod/event_handlers/mod_rayo/mod_rayo.c index 7baaf5f46f..6370d88048 100644 --- a/src/mod/event_handlers/mod_rayo/mod_rayo.c +++ b/src/mod/event_handlers/mod_rayo/mod_rayo.c @@ -3688,7 +3688,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_rayo_load) "" "0123456789*#]]>" ""); - + rayo_add_cmd_alias("output_bad", + ""); return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/event_handlers/mod_rayo/rayo_output_component.c b/src/mod/event_handlers/mod_rayo/rayo_output_component.c index 82fd0aa8b2..f92d994a64 100644 --- a/src/mod/event_handlers/mod_rayo/rayo_output_component.c +++ b/src/mod/event_handlers/mod_rayo/rayo_output_component.c @@ -126,12 +126,19 @@ static iks *start_call_output_component(struct rayo_actor *call, struct rayo_mes switch_core_session_t *session = (switch_core_session_t *)session_data; struct rayo_component *output_component = NULL; iks *output = iks_find(iq, "output"); + iks *document = NULL; /* validate output attributes */ if (!VALIDATE_RAYO_OUTPUT(output)) { return iks_new_error(iq, STANZA_ERROR_BAD_REQUEST); } + /* check if exists */ + document = iks_find(output, "document"); + if (!document) { + return iks_new_error(iq, STANZA_ERROR_BAD_REQUEST); + } + output_component = create_output_component(call, RAT_CALL_COMPONENT, output, iks_find_attrib(iq, "from")); return start_call_output(output_component, session, output, iq); } @@ -144,6 +151,7 @@ static iks *start_mixer_output_component(struct rayo_actor *mixer, struct rayo_m iks *iq = msg->payload; struct rayo_component *component = NULL; iks *output = iks_find(iq, "output"); + iks *document = NULL; switch_stream_handle_t stream = { 0 }; /* validate output attributes */ @@ -151,6 +159,12 @@ static iks *start_mixer_output_component(struct rayo_actor *mixer, struct rayo_m return iks_new_error(iq, STANZA_ERROR_BAD_REQUEST); } + /* check if exists */ + document = iks_find(output, "document"); + if (!document) { + return iks_new_error(iq, STANZA_ERROR_BAD_REQUEST); + } + component = create_output_component(mixer, RAT_MIXER_COMPONENT, output, iks_find_attrib(iq, "from")); /* build conference command */ From d285e798676e7a376c05c8de54abf031946d549a Mon Sep 17 00:00:00 2001 From: Chris Rienzo Date: Tue, 6 Aug 2013 14:52:56 -0400 Subject: [PATCH 10/39] mod_rayo: fix crash on originate error --- src/mod/event_handlers/mod_rayo/mod_rayo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mod/event_handlers/mod_rayo/mod_rayo.c b/src/mod/event_handlers/mod_rayo/mod_rayo.c index 6370d88048..3aa255f833 100644 --- a/src/mod/event_handlers/mod_rayo/mod_rayo.c +++ b/src/mod/event_handlers/mod_rayo/mod_rayo.c @@ -1907,6 +1907,7 @@ static void *SWITCH_THREAD_FUNC rayo_dial_thread(switch_thread_t *thread, void * char *dial_to_dup = NULL; const char *dial_from = iks_find_attrib(dial, "from"); const char *dial_timeout_ms = iks_find_attrib(dial, "timeout"); + const char *uuid = NULL; struct dial_gateway *gateway = NULL; struct rayo_call *call = NULL; switch_stream_handle_t stream = { 0 }; @@ -1917,6 +1918,7 @@ static void *SWITCH_THREAD_FUNC rayo_dial_thread(switch_thread_t *thread, void * call->dcp_jid = switch_core_strdup(RAYO_POOL(call), dcp_jid); call->dial_id = iks_find_attrib(iq, "id"); switch_log_printf(SWITCH_CHANNEL_UUID_LOG(rayo_call_get_uuid(call)), SWITCH_LOG_INFO, "%s has control of call\n", dcp_jid); + uuid = switch_core_strdup(dtdata->pool, rayo_call_get_uuid(call)); /* set rayo channel variables so channel originate event can be identified as coming from Rayo */ stream.write_function(&stream, "{origination_uuid=%s,rayo_dcp_jid=%s,rayo_call_jid=%s", @@ -2016,19 +2018,17 @@ static void *SWITCH_THREAD_FUNC rayo_dial_thread(switch_thread_t *thread, void * /* response will be sent when originate event is received- otherwise error is returned */ if (switch_api_execute("originate", stream.data, NULL, &api_stream) == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_UUID_LOG(rayo_call_get_uuid(call)), SWITCH_LOG_DEBUG, "Got originate result: %s\n", (char *)api_stream.data); + switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_DEBUG, "Got originate result: %s\n", (char *)api_stream.data); /* check for failure */ if (strncmp("+OK", api_stream.data, strlen("+OK"))) { - switch_log_printf(SWITCH_CHANNEL_UUID_LOG(rayo_call_get_uuid(call)), SWITCH_LOG_INFO, "Failed to originate call\n"); + switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_INFO, "Failed to originate call\n"); if (call->dial_id) { /* map failure reason to iq error */ if (!strncmp("-ERR DESTINATION_OUT_OF_ORDER", api_stream.data, strlen("-ERR DESTINATION_OUT_OF_ORDER"))) { /* this -ERR is received when out of sessions */ response = iks_new_error(iq, STANZA_ERROR_RESOURCE_CONSTRAINT); - } else { - response = iks_new_error_detailed(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, api_stream.data); } } } From 68253e37488a3d62af8d1887789efd6dbcc6b900 Mon Sep 17 00:00:00 2001 From: Chris Rienzo Date: Tue, 6 Aug 2013 15:30:22 -0400 Subject: [PATCH 11/39] FS-5668 --resolve mod_rayo: offer from/to do not match SIP --- src/mod/event_handlers/mod_rayo/mod_rayo.c | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/mod/event_handlers/mod_rayo/mod_rayo.c b/src/mod/event_handlers/mod_rayo/mod_rayo.c index 3aa255f833..79d2179053 100644 --- a/src/mod/event_handlers/mod_rayo/mod_rayo.c +++ b/src/mod/event_handlers/mod_rayo/mod_rayo.c @@ -2728,12 +2728,35 @@ static iks *rayo_create_offer(struct rayo_call *call, switch_core_session_t *ses switch_caller_profile_t *profile = switch_channel_get_caller_profile(channel); iks *presence = iks_new("presence"); iks *offer = iks_insert(presence, "offer"); + const char *val; iks_insert_attrib(presence, "from", RAYO_JID(call)); - iks_insert_attrib(offer, "from", profile->caller_id_number); - iks_insert_attrib(offer, "to", profile->destination_number); iks_insert_attrib(offer, "xmlns", RAYO_NS); + if ((val = switch_channel_get_variable(channel, "sip_from_uri"))) { + /* is a SIP call - pass the URI */ + if (!strchr(val, ':')) { + iks_insert_attrib_printf(offer, "from", "sip:%s", val); + } else { + iks_insert_attrib(offer, "from", val); + } + } else { + /* pass caller ID */ + iks_insert_attrib(offer, "from", profile->caller_id_number); + } + + if ((val = switch_channel_get_variable(channel, "sip_to_uri"))) { + /* is a SIP call - pass the URI */ + if (!strchr(val, ':')) { + iks_insert_attrib_printf(offer, "to", "sip:%s", val); + } else { + iks_insert_attrib(offer, "to", val); + } + } else { + /* pass dialed number */ + iks_insert_attrib(offer, "to", profile->destination_number); + } + /* add signaling headers */ { switch_event_header_t *var; From e94c931102cf056d0d1d6dcfb023d5621d829534 Mon Sep 17 00:00:00 2001 From: Chris Rienzo Date: Tue, 6 Aug 2013 16:21:22 -0400 Subject: [PATCH 12/39] FS-5679 --resolve mod_rayo: SIP 180 doesn't result in ringing event --- src/mod/event_handlers/mod_rayo/mod_rayo.c | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/mod/event_handlers/mod_rayo/mod_rayo.c b/src/mod/event_handlers/mod_rayo/mod_rayo.c index 79d2179053..6798f70f06 100644 --- a/src/mod/event_handlers/mod_rayo/mod_rayo.c +++ b/src/mod/event_handlers/mod_rayo/mod_rayo.c @@ -129,6 +129,8 @@ struct rayo_call { const char *dial_id; /** channel destroy event */ switch_event_t *end_event; + /** True if ringing event sent to client */ + int ringing_sent; }; /** @@ -1031,6 +1033,7 @@ static struct rayo_call *rayo_call_init(struct rayo_call *call, switch_memory_po call->dcp_jid = ""; call->idle_start_time = switch_micro_time_now(); call->joined = 0; + call->ringing_sent = 0; switch_core_hash_init(&call->pcps, pool); switch_safe_free(call_jid); @@ -2550,13 +2553,21 @@ static void on_call_answer_event(struct rayo_client *rclient, switch_event_t *ev */ static void on_call_ringing_event(struct rayo_client *rclient, switch_event_t *event) { - struct rayo_call *call = RAYO_CALL_LOCATE(switch_event_get_header(event, "Unique-ID")); - if (call) { - iks *revent = iks_new_presence("ringing", RAYO_NS, - switch_event_get_header(event, "variable_rayo_call_jid"), - switch_event_get_header(event, "variable_rayo_dcp_jid")); - RAYO_SEND_MESSAGE(call, RAYO_JID(rclient), revent); - RAYO_UNLOCK(call); + const char *call_direction = switch_event_get_header(event, "Call-Direction"); + if (call_direction && !strcmp(call_direction, "outbound")) { + struct rayo_call *call = RAYO_CALL_LOCATE(switch_event_get_header(event, "Unique-ID")); + if (call) { + switch_mutex_lock(RAYO_ACTOR(call)->mutex); + if (!call->ringing_sent) { + iks *revent = iks_new_presence("ringing", RAYO_NS, + switch_event_get_header(event, "variable_rayo_call_jid"), + switch_event_get_header(event, "variable_rayo_dcp_jid")); + call->ringing_sent = 1; + RAYO_SEND_MESSAGE(call, RAYO_JID(rclient), revent); + RAYO_UNLOCK(call); + } + switch_mutex_unlock(RAYO_ACTOR(call)->mutex); + } } } @@ -2651,6 +2662,7 @@ static void rayo_client_handle_event(struct rayo_client *rclient, switch_event_t case SWITCH_EVENT_CHANNEL_ORIGINATE: on_call_originate_event(rclient, event); break; + case SWITCH_EVENT_CHANNEL_PROGRESS: case SWITCH_EVENT_CHANNEL_PROGRESS_MEDIA: on_call_ringing_event(rclient, event); break; @@ -3598,6 +3610,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_rayo_load) switch_event_bind(modname, SWITCH_EVENT_CHANNEL_ORIGINATE, NULL, route_call_event, NULL); switch_event_bind(modname, SWITCH_EVENT_CHANNEL_PROGRESS_MEDIA, NULL, route_call_event, NULL); + switch_event_bind(modname, SWITCH_EVENT_CHANNEL_PROGRESS, NULL, route_call_event, NULL); switch_event_bind(modname, SWITCH_EVENT_CHANNEL_ANSWER, NULL, route_call_event, NULL); switch_event_bind(modname, SWITCH_EVENT_CHANNEL_BRIDGE, NULL, route_call_event, NULL); switch_event_bind(modname, SWITCH_EVENT_CHANNEL_UNBRIDGE, NULL, route_call_event, NULL); From 14ca0b54987dd37c93864c9a37f7f3c6747c435f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 7 Aug 2013 20:40:16 +0500 Subject: [PATCH 13/39] FS-5655 --resolve --- Freeswitch.2010.express.sln | 2 ++ Freeswitch.2010.sln | 2 ++ Freeswitch.2012.sln | 2 ++ libs/spandsp/src/alloc.c | 11 ++++++++++- libs/spandsp/src/libspandsp.2010.vcxproj | 1 + libs/spandsp/src/libspandsp.2010.vcxproj.filters | 3 +++ libs/spandsp/src/libspandsp.2012.vcxproj | 1 + libs/spandsp/src/libspandsp.2012.vcxproj.filters | 3 +++ 8 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Freeswitch.2010.express.sln b/Freeswitch.2010.express.sln index 6b7c5fde3b..e554a13076 100644 --- a/Freeswitch.2010.express.sln +++ b/Freeswitch.2010.express.sln @@ -2081,9 +2081,11 @@ Global {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|Win32.ActiveCfg = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|Win32.Build.0 = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|x64.ActiveCfg = All|Win32 + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|x64.Build.0 = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|Win32.ActiveCfg = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|Win32.Build.0 = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|x64.ActiveCfg = All|Win32 + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|x64.Build.0 = All|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Freeswitch.2010.sln b/Freeswitch.2010.sln index 65ade0314f..4148d2ddc5 100644 --- a/Freeswitch.2010.sln +++ b/Freeswitch.2010.sln @@ -3801,11 +3801,13 @@ Global {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|Win32.ActiveCfg = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|Win32.Build.0 = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|x64.ActiveCfg = All|Win32 + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|x64.Build.0 = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|x64 Setup.ActiveCfg = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|x86 Setup.ActiveCfg = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|Win32.ActiveCfg = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|Win32.Build.0 = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|x64.ActiveCfg = All|Win32 + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|x64.Build.0 = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|x64 Setup.ActiveCfg = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|x86 Setup.ActiveCfg = All|Win32 EndGlobalSection diff --git a/Freeswitch.2012.sln b/Freeswitch.2012.sln index 242ebc85b6..346914e690 100644 --- a/Freeswitch.2012.sln +++ b/Freeswitch.2012.sln @@ -3811,11 +3811,13 @@ Global {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|Win32.ActiveCfg = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|Win32.Build.0 = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|x64.ActiveCfg = All|Win32 + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|x64.Build.0 = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|x64 Setup.ActiveCfg = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Debug|x86 Setup.ActiveCfg = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|Win32.ActiveCfg = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|Win32.Build.0 = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|x64.ActiveCfg = All|Win32 + {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|x64.Build.0 = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|x64 Setup.ActiveCfg = All|Win32 {85F0CF8C-C7AB-48F6-BA19-CC94CF87F981}.Release|x86 Setup.ActiveCfg = All|Win32 EndGlobalSection diff --git a/libs/spandsp/src/alloc.c b/libs/spandsp/src/alloc.c index d02291248c..eee961c615 100644 --- a/libs/spandsp/src/alloc.c +++ b/libs/spandsp/src/alloc.c @@ -48,6 +48,13 @@ #include "spandsp/telephony.h" #include "spandsp/alloc.h" +static void *fake_aligned_alloc(size_t alignment, size_t size); + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4232) /* address of dllimport is not static, identity not guaranteed */ +#endif + span_alloc_t __span_alloc = malloc; #if defined(HAVE_ALIGNED_ALLOC) span_aligned_alloc_t __span_aligned_alloc = aligned_alloc; @@ -62,7 +69,9 @@ span_aligned_alloc_t __span_aligned_alloc = fake_aligned_alloc; span_realloc_t __span_realloc = realloc; span_free_t __span_free = free; -static void *fake_aligned_alloc(size_t alignment, size_t size); +#ifdef _MSC_VER +#pragma warning(pop) +#endif #if defined(HAVE_ALIGNED_ALLOC) #elif defined(HAVE_MEMALIGN) diff --git a/libs/spandsp/src/libspandsp.2010.vcxproj b/libs/spandsp/src/libspandsp.2010.vcxproj index 1697ba19a5..8bb87b58c6 100644 --- a/libs/spandsp/src/libspandsp.2010.vcxproj +++ b/libs/spandsp/src/libspandsp.2010.vcxproj @@ -157,6 +157,7 @@ + diff --git a/libs/spandsp/src/libspandsp.2010.vcxproj.filters b/libs/spandsp/src/libspandsp.2010.vcxproj.filters index 05763b180c..cc34e6c278 100644 --- a/libs/spandsp/src/libspandsp.2010.vcxproj.filters +++ b/libs/spandsp/src/libspandsp.2010.vcxproj.filters @@ -283,6 +283,9 @@ Source Files + + Source Files + diff --git a/libs/spandsp/src/libspandsp.2012.vcxproj b/libs/spandsp/src/libspandsp.2012.vcxproj index 92ddbbe0c9..dd99dbc2d9 100644 --- a/libs/spandsp/src/libspandsp.2012.vcxproj +++ b/libs/spandsp/src/libspandsp.2012.vcxproj @@ -161,6 +161,7 @@ + diff --git a/libs/spandsp/src/libspandsp.2012.vcxproj.filters b/libs/spandsp/src/libspandsp.2012.vcxproj.filters index 05763b180c..cc34e6c278 100644 --- a/libs/spandsp/src/libspandsp.2012.vcxproj.filters +++ b/libs/spandsp/src/libspandsp.2012.vcxproj.filters @@ -283,6 +283,9 @@ Source Files + + Source Files + From 11d6c0877aed8d56557c068e5c17435f873e75e0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 7 Aug 2013 20:59:08 +0500 Subject: [PATCH 14/39] FS-5665 --resolve this should push the extra ones into the variable and convert it to an array --- src/mod/endpoints/mod_sofia/sofia.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index c9c09b233e..da0cd3deac 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -8496,7 +8496,18 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia if (call_info->ci_params && (msg_params_find(call_info->ci_params, "answer-after=0"))) { switch_channel_set_variable(channel, "sip_auto_answer_detected", "true"); } + switch_channel_set_variable(channel, "sip_call_info", call_info_str); + + call_info = call_info->ci_next; + + while (call_info) { + call_info_str = sip_header_as_string(nh->nh_home, (void *) call_info); + switch_channel_add_variable_var_check(channel, "sip_call_info", call_info_str, SWITCH_FALSE, SWITCH_STACK_PUSH); + call_info = call_info->ci_next; + } + + } else if (sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE)) { char buf[128] = ""; char *sql; From 116ebc02442e69b7470ac96fd4280635f64b6ca8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 7 Aug 2013 21:22:26 +0500 Subject: [PATCH 15/39] FS-5661 --resolve --- src/include/switch_scheduler.h | 1 + src/mod/applications/mod_commands/mod_commands.c | 6 ++++-- src/mod/applications/mod_dptools/mod_dptools.c | 4 +++- src/switch_scheduler.c | 11 +++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/include/switch_scheduler.h b/src/include/switch_scheduler.h index 8d9bd9ca1a..59997a006d 100644 --- a/src/include/switch_scheduler.h +++ b/src/include/switch_scheduler.h @@ -43,6 +43,7 @@ SWITCH_BEGIN_EXTERN_C int64_t created; int64_t runtime; uint32_t cmd_id; + uint32_t repeat; char *group; void *cmd_arg; uint32_t task_id; diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index ef91f36a8d..fc74c3dd65 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -3164,7 +3164,7 @@ SWITCH_STANDARD_API(uuid_broadcast_function) return SWITCH_STATUS_SUCCESS; } -#define SCHED_BROADCAST_SYNTAX "[+]