提交 88587ec0 authored 作者: Steve Underwood's avatar Steve Underwood

Minor tweaks from cleaning up spandsp

上级 a55d70ed
...@@ -257,10 +257,10 @@ then ...@@ -257,10 +257,10 @@ then
esac esac
fi fi
#AC_DEFINE([SPANDSP_SUPPORT_T42], [1], [Support T.42 JPEG compression]) AC_DEFINE([SPANDSP_SUPPORT_T42], [1], [Support T.42 JPEG compression])
SPANDSP_SUPPORT_T42="#undef SPANDSP_SUPPORT_T42" SPANDSP_SUPPORT_T42="#define SPANDSP_SUPPORT_T42 1"
#AC_DEFINE([SPANDSP_SUPPORT_T43], [1], [Support T.43 JBIG gray and colour compression]) AC_DEFINE([SPANDSP_SUPPORT_T43], [1], [Support T.43 JBIG gray and colour compression])
SPANDSP_SUPPORT_T43="#undef SPANDSP_SUPPORT_T43" SPANDSP_SUPPORT_T43="#define SPANDSP_SUPPORT_T43 1"
#AC_DEFINE([SPANDSP_SUPPORT_V32BIS], [1], [Support the V.32bis modem]) #AC_DEFINE([SPANDSP_SUPPORT_V32BIS], [1], [Support the V.32bis modem])
SPANDSP_SUPPORT_V32BIS="#undef SPANDSP_SUPPORT_V32BIS" SPANDSP_SUPPORT_V32BIS="#undef SPANDSP_SUPPORT_V32BIS"
#AC_DEFINE([SPANDSP_SUPPORT_V34], [1], [Support the V.34 FAX modem]) #AC_DEFINE([SPANDSP_SUPPORT_V34], [1], [Support the V.34 FAX modem])
......
...@@ -21,12 +21,6 @@ ...@@ -21,12 +21,6 @@
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software * License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Based in part on a single channel G.722 codec which is:
*
* Copyright (c) CMU 1993
* Computer Science, Speech Group
* Chengxiang Lu and Alex Hauptmann
*/ */
/*! \file */ /*! \file */
......
...@@ -21,15 +21,8 @@ ...@@ -21,15 +21,8 @@
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software * License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Based on a single channel G.722 codec which is:
*
***** Copyright (c) CMU 1993 *****
* Computer Science, Speech Group
* Chengxiang Lu and Alex Hauptmann
*/ */
/*! \file */ /*! \file */
#if !defined(_SPANDSP_G722_H_) #if !defined(_SPANDSP_G722_H_)
......
...@@ -690,9 +690,24 @@ SPAN_DECLARE(int) t30_set_supported_compressions(t30_state_t *s, int supported_c ...@@ -690,9 +690,24 @@ SPAN_DECLARE(int) t30_set_supported_compressions(t30_state_t *s, int supported_c
| T4_SUPPORT_COMPRESSION_T6 | T4_SUPPORT_COMPRESSION_T6
| T4_SUPPORT_COMPRESSION_T85 | T4_SUPPORT_COMPRESSION_T85
| T4_SUPPORT_COMPRESSION_T85_L0 | T4_SUPPORT_COMPRESSION_T85_L0
#if defined(SPANDSP_SUPPORT_T88)
| T4_SUPPORT_COMPRESSION_T88
#endif
//| T4_SUPPORT_COMPRESSION_T81 //| T4_SUPPORT_COMPRESSION_T81
#if defined(SPANDSP_SUPPORT_T43) #if defined(SPANDSP_SUPPORT_T43)
| T4_SUPPORT_COMPRESSION_T43 | T4_SUPPORT_COMPRESSION_T43
#endif
#if defined(SPANDSP_SUPPORT_T45)
| T4_SUPPORT_COMPRESSION_T45
#endif
#if 0
| T4_SUPPORT_COMPRESSION_GRAYSCALE
| T4_SUPPORT_COMPRESSION_COLOUR
| T4_SUPPORT_COMPRESSION_12BIT
| T4_SUPPORT_COMPRESSION_COLOUR_TO_GRAY
| T4_SUPPORT_COMPRESSION_GRAY_TO_BILEVEL
| T4_SUPPORT_COMPRESSION_COLOUR_TO_BILEVEL
| T4_SUPPORT_COMPRESSION_RESCALING
#endif #endif
| 0; | 0;
s->supported_compressions = supported_compressions; s->supported_compressions = supported_compressions;
......
...@@ -48,7 +48,6 @@ ...@@ -48,7 +48,6 @@
#include "floating_fudge.h" #include "floating_fudge.h"
#include <tiffio.h> #include <tiffio.h>
#include <assert.h> #include <assert.h>
#include <jpeglib.h>
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
#include "spandsp/fast_convert.h" #include "spandsp/fast_convert.h"
...@@ -719,15 +718,17 @@ static void jpg_encode_error_exit(j_common_ptr cinfo) ...@@ -719,15 +718,17 @@ static void jpg_encode_error_exit(j_common_ptr cinfo)
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
/* This is the error catcher */ /* This is the error catcher */
#ifndef WIN32
static struct jpeg_error_mgr encode_error_handler = static struct jpeg_error_mgr encode_error_handler =
{ {
#if defined(_MSC_VER) || defined(__sunos) || defined(__solaris) || defined(__sun)
jpg_encode_error_exit,
0,
jpg_encode_error_exit
#else
.error_exit = jpg_encode_error_exit, .error_exit = jpg_encode_error_exit,
.output_message = jpg_encode_error_exit .output_message = jpg_encode_error_exit
};
#else
static struct jpeg_error_mgr encode_error_handler = {jpg_encode_error_exit,0,jpg_encode_error_exit};
#endif #endif
};
static int t42_srgb_to_itulab_jpeg(t42_encode_state_t *s) static int t42_srgb_to_itulab_jpeg(t42_encode_state_t *s)
{ {
...@@ -1032,15 +1033,17 @@ static void jpg_decode_error_exit(j_common_ptr cinfo) ...@@ -1032,15 +1033,17 @@ static void jpg_decode_error_exit(j_common_ptr cinfo)
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
/* This is the error catcher */ /* This is the error catcher */
#ifndef WIN32
static struct jpeg_error_mgr decode_error_handler = static struct jpeg_error_mgr decode_error_handler =
{ {
#if defined(_MSC_VER) || defined(__sunos) || defined(__solaris) || defined(__sun)
jpg_decode_error_exit,
0,
jpg_decode_error_exit
#else
.error_exit = jpg_decode_error_exit, .error_exit = jpg_decode_error_exit,
.output_message = jpg_decode_error_exit .output_message = jpg_decode_error_exit
};
#else
static struct jpeg_error_mgr decode_error_handler = {jpg_decode_error_exit,0,jpg_decode_error_exit};
#endif #endif
};
static int t42_itulab_jpeg_to_srgb(t42_decode_state_t *s) static int t42_itulab_jpeg_to_srgb(t42_decode_state_t *s)
{ {
......
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
#endif #endif
#include <time.h> #include <time.h>
#include "floating_fudge.h" #include "floating_fudge.h"
#include <jpeglib.h>
#include <setjmp.h> #include <setjmp.h>
#include "spandsp/telephony.h" #include "spandsp/telephony.h"
......
...@@ -112,6 +112,7 @@ noinst_PROGRAMS = ademco_contactid_tests \ ...@@ -112,6 +112,7 @@ noinst_PROGRAMS = ademco_contactid_tests \
t4_tests \ t4_tests \
t4_t6_tests \ t4_t6_tests \
t42_tests \ t42_tests \
t43_tests \
t81_t82_arith_coding_tests \ t81_t82_arith_coding_tests \
t85_tests \ t85_tests \
time_scale_tests \ time_scale_tests \
...@@ -325,6 +326,9 @@ t4_t6_tests_LDADD = $(LIBDIR) -lspandsp ...@@ -325,6 +326,9 @@ t4_t6_tests_LDADD = $(LIBDIR) -lspandsp
t42_tests_SOURCES = t42_tests.c t42_tests_SOURCES = t42_tests.c
t42_tests_LDADD = $(LIBDIR) -lspandsp t42_tests_LDADD = $(LIBDIR) -lspandsp
t43_tests_SOURCES = t43_tests.c
t43_tests_LDADD = $(LIBDIR) -lspandsp
t81_t82_arith_coding_tests_SOURCES = t81_t82_arith_coding_tests.c t81_t82_arith_coding_tests_SOURCES = t81_t82_arith_coding_tests.c
t81_t82_arith_coding_tests_LDADD = $(LIBDIR) -lspandsp t81_t82_arith_coding_tests_LDADD = $(LIBDIR) -lspandsp
......
...@@ -490,6 +490,7 @@ int main(int argc, char *argv[]) ...@@ -490,6 +490,7 @@ int main(int argc, char *argv[])
int noise_level; int noise_level;
int code_to_look_up; int code_to_look_up;
int scan_line_time; int scan_line_time;
int colour_enabled;
t38_stats_t t38_stats; t38_stats_t t38_stats;
t30_stats_t t30_stats; t30_stats_t t30_stats;
logging_state_t *logging; logging_state_t *logging;
...@@ -528,14 +529,18 @@ int main(int argc, char *argv[]) ...@@ -528,14 +529,18 @@ int main(int argc, char *argv[])
scan_line_time = 0; scan_line_time = 0;
decode_file_name = NULL; decode_file_name = NULL;
code_to_look_up = -1; code_to_look_up = -1;
colour_enabled = FALSE;
t38_transport = T38_TRANSPORT_UDPTL; t38_transport = T38_TRANSPORT_UDPTL;
while ((opt = getopt(argc, argv, "c:d:D:efFgH:i:Ilm:M:n:p:s:S:tT:u:v:z:")) != -1) while ((opt = getopt(argc, argv, "c:Cd:D:efFgH:i:Ilm:M:n:p:s:S:tT:u:v:z:")) != -1)
{ {
switch (opt) switch (opt)
{ {
case 'c': case 'c':
code_to_look_up = atoi(optarg); code_to_look_up = atoi(optarg);
break; break;
case 'C':
colour_enabled = TRUE;
break;
case 'd': case 'd':
decode_file_name = optarg; decode_file_name = optarg;
break; break;
...@@ -845,7 +850,7 @@ int main(int argc, char *argv[]) ...@@ -845,7 +850,7 @@ int main(int argc, char *argv[])
| T4_SUPPORT_LENGTH_US_LETTER | T4_SUPPORT_LENGTH_US_LETTER
| T4_SUPPORT_LENGTH_US_LEGAL | T4_SUPPORT_LENGTH_US_LEGAL
| T4_SUPPORT_LENGTH_UNLIMITED); | T4_SUPPORT_LENGTH_UNLIMITED);
#if 0 #if 1
t30_set_supported_bilevel_resolutions(t30_state[i], t30_set_supported_bilevel_resolutions(t30_state[i],
T4_SUPPORT_RESOLUTION_R8_STANDARD T4_SUPPORT_RESOLUTION_R8_STANDARD
| T4_SUPPORT_RESOLUTION_R8_FINE | T4_SUPPORT_RESOLUTION_R8_FINE
...@@ -880,17 +885,20 @@ int main(int argc, char *argv[]) ...@@ -880,17 +885,20 @@ int main(int argc, char *argv[])
| T4_SUPPORT_RESOLUTION_600_1200 | T4_SUPPORT_RESOLUTION_600_1200
| T4_SUPPORT_RESOLUTION_1200_1200); | T4_SUPPORT_RESOLUTION_1200_1200);
#endif #endif
#if 1 if (colour_enabled)
t30_set_supported_colour_resolutions(t30_state[i], 0); {
#else t30_set_supported_colour_resolutions(t30_state[i],
t30_set_supported_colour_resolutions(t30_state[i], T4_SUPPORT_RESOLUTION_100_100
T4_SUPPORT_RESOLUTION_100_100 | T4_SUPPORT_RESOLUTION_200_200
| T4_SUPPORT_RESOLUTION_200_200 | T4_SUPPORT_RESOLUTION_300_300
| T4_SUPPORT_RESOLUTION_300_300 | T4_SUPPORT_RESOLUTION_400_400
| T4_SUPPORT_RESOLUTION_400_400 | T4_SUPPORT_RESOLUTION_600_600
| T4_SUPPORT_RESOLUTION_600_600 | T4_SUPPORT_RESOLUTION_1200_1200);
| T4_SUPPORT_RESOLUTION_1200_1200); }
#endif else
{
t30_set_supported_colour_resolutions(t30_state[i], 0);
}
t30_set_supported_output_compressions(t30_state[i], T4_SUPPORT_COMPRESSION_T4_2D); t30_set_supported_output_compressions(t30_state[i], T4_SUPPORT_COMPRESSION_T4_2D);
t30_set_ecm_capability(t30_state[i], use_ecm); t30_set_ecm_capability(t30_state[i], use_ecm);
t30_set_supported_compressions(t30_state[i], t30_set_supported_compressions(t30_state[i],
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
run_fax_test() run_fax_test()
{ {
rm -f fax_tests_1.tif rm -f fax_tests.tif
echo ./fax_tests ${OPTS} -i ${FILE} echo ./fax_tests ${OPTS} -i ${FILE}
./fax_tests ${OPTS} -i ${FILE} >xyzzy 2>xyzzy2 ./fax_tests ${OPTS} -i ${FILE} >xyzzy 2>xyzzy2
RETVAL=$? RETVAL=$?
...@@ -35,12 +35,87 @@ run_fax_test() ...@@ -35,12 +35,87 @@ run_fax_test()
echo fax_tests failed! echo fax_tests failed!
exit $RETVAL exit $RETVAL
fi fi
rm -f fax_tests_1.tif rm -f fax_tests.tif
echo tested ${FILE} echo tested ${FILE}
} }
run_colour_fax_test()
{
rm -f fax_tests.tif
echo ./fax_tests ${OPTS} -i ${IN_FILE}
./fax_tests ${OPTS} -i ${IN_FILE} >xyzzy 2>xyzzy2
RETVAL=$?
if [ $RETVAL != 0 ]
then
echo fax_tests failed!
exit $RETVAL
fi
# Now use tiffcmp to check the results. It will return non-zero if any page images differ. The -t
# option means the normal differences in tags will be ignored.
tiffcmp -t ${OUT_FILE} fax_tests.tif >/dev/null
RETVAL=$?
if [ $RETVAL != 0 ]
then
echo fax_tests failed!
exit $RETVAL
fi
rm -f fax_tests.tif
echo tested ${IN_FILE} to ${OUT_FILE}
}
ITUTESTS_DIR=../test-data/itu/fax ITUTESTS_DIR=../test-data/itu/fax
TIFFFX_DIR=../test-data/itu/tiff-fx
LOCALTESTS_DIR=../test-data/local
# Colour/gray -> bilevel by not allowing ECM
for OPTS in "-p AA" "-p TT" "-p GG" "-p TG" "-p GT"
do
IN_FILE="${LOCALTESTS_DIR}/lenna-colour.tif"
OUT_FILE="${LOCALTESTS_DIR}/lenna-colour-bilevel.tif"
run_colour_fax_test
IN_FILE="${LOCALTESTS_DIR}/lenna-bw.tif"
OUT_FILE="${LOCALTESTS_DIR}/lenna-bw-bilevel.tif"
run_colour_fax_test
IN_FILE="${TIFFFX_DIR}/c03x_02x.tif"
OUT_FILE="${TIFFFX_DIR}/c03x_02x.tif"
run_colour_fax_test
IN_FILE="${TIFFFX_DIR}/l02x_02x.tif"
OUT_FILE="${TIFFFX_DIR}/l02x_02x.tif"
run_colour_fax_test
IN_FILE="${TIFFFX_DIR}/l04x_02x.tif"
OUT_FILE="${TIFFFX_DIR}/l04x_02x.tif"
run_colour_fax_test
done
# Colour/gray -> colour/gray by allowing ECM
for OPTS in "-p AA -C -e" "-p TT -C -e" "-p GG -C -e" "-p TG -C -e" "-p GT -C -e"
do
IN_FILE="${LOCALTESTS_DIR}/lenna-colour.tif"
OUT_FILE="${LOCALTESTS_DIR}/lenna-colour.tif"
run_colour_fax_test
IN_FILE="${LOCALTESTS_DIR}/lenna-bw.tif"
OUT_FILE="${LOCALTESTS_DIR}/lenna-bw.tif"
run_colour_fax_test
IN_FILE="${TIFFFX_DIR}/c03x_02x.tif"
OUT_FILE="${TIFFFX_DIR}/c03x_02x.tif"
run_colour_fax_test
IN_FILE="${TIFFFX_DIR}/l02x_02x.tif"
OUT_FILE="${TIFFFX_DIR}/l02x_02x.tif"
run_colour_fax_test
IN_FILE="${TIFFFX_DIR}/l04x_02x.tif"
OUT_FILE="${TIFFFX_DIR}/l04x_02x.tif"
run_colour_fax_test
done
# Bi-level tests
for OPTS in "-p AA" "-p AA -e" "-p TT" "-p TT -e" "-p GG" "-p GG -e" "-p TG" "-p TG -e" "-p GT" "-p GT -e" for OPTS in "-p AA" "-p AA -e" "-p TT" "-p TT -e" "-p GG" "-p GG -e" "-p TG" "-p TG -e" "-p GT" "-p GT -e"
do do
FILE="${ITUTESTS_DIR}/itutests.tif" FILE="${ITUTESTS_DIR}/itutests.tif"
......
...@@ -157,7 +157,8 @@ int main(int argc, char *argv[]) ...@@ -157,7 +157,8 @@ int main(int argc, char *argv[])
TIFF_FX_init(); TIFF_FX_init();
#endif #endif
set_lab_illuminant(&lab_param, 0.9638f, 1.0f, 0.8245f); /* The default luminant is D50 */
set_lab_illuminant(&lab_param, 96.422f, 100.000f, 82.521f);
set_lab_gamut(&lab_param, 0, 100, -85, 85, -75, 125, FALSE); set_lab_gamut(&lab_param, 0, 100, -85, 85, -75, 125, FALSE);
source_file = (argc > 1) ? argv[1] : IN_FILE_NAME; source_file = (argc > 1) ? argv[1] : IN_FILE_NAME;
...@@ -218,7 +219,8 @@ int main(int argc, char *argv[]) ...@@ -218,7 +219,8 @@ int main(int argc, char *argv[])
#endif #endif
lab_params_t lab; lab_params_t lab;
set_lab_illuminant(&lab, 0.9638f, 1.0f, 0.8245f); /* The default luminant is D50 */
set_lab_illuminant(&lab, 96.422f, 100.000f, 82.521f);
set_lab_gamut(&lab, 0, 100, -85, 85, -75, 125, FALSE); set_lab_gamut(&lab, 0, 100, -85, 85, -75, 125, FALSE);
lab_to_srgb(&lab, colour_map, colour_map, 256); lab_to_srgb(&lab, colour_map, colour_map, 256);
for (i = 0; i < (1 << bits_per_pixel); i++) for (i = 0; i < (1 << bits_per_pixel); i++)
...@@ -447,12 +449,13 @@ int main(int argc, char *argv[]) ...@@ -447,12 +449,13 @@ int main(int argc, char *argv[])
if (photometric == PHOTOMETRIC_ITULAB) if (photometric == PHOTOMETRIC_ITULAB)
{ {
printf("YYY ITULAB\n"); printf("YYY ITULAB\n");
#if 0
if (!t42_itulab_to_itulab(logging, (tdata_t) &outptr, &outsize, data, off, w, h)) if (!t42_itulab_to_itulab(logging, (tdata_t) &outptr, &outsize, data, off, w, h, 3))
{ {
printf("Failed to convert to ITULAB\n"); printf("Failed to convert to ITULAB\n");
return 1; return 1;
} }
#endif
free(data); free(data);
data = (uint8_t *) outptr; data = (uint8_t *) outptr;
off = outsize; off = outsize;
...@@ -470,11 +473,12 @@ int main(int argc, char *argv[]) ...@@ -470,11 +473,12 @@ int main(int argc, char *argv[])
lab_to_srgb(&lab_param, data, data, w*h); lab_to_srgb(&lab_param, data, data, w*h);
break; break;
case PHOTOMETRIC_ITULAB: case PHOTOMETRIC_ITULAB:
set_lab_illuminant(&lab_param, 0.9638f, 1.0f, 0.8245f); /* The default luminant is D50 */
set_lab_illuminant(&lab_param, 96.422f, 100.000f, 82.521f);
set_lab_gamut(&lab_param, 0, 100, -85, 85, -75, 125, FALSE); set_lab_gamut(&lab_param, 0, 100, -85, 85, -75, 125, FALSE);
break; break;
} }
if (!t42_srgb_to_itulab(logging, &lab_param, (tdata_t) &outptr, &outsize, data, off, w, h)) //if (!t42_srgb_to_itulab_jpeg(logging, &lab_param, (tdata_t) &outptr, &outsize, data, off, w, h, 3))
{ {
printf("Failed to convert to ITULAB\n"); printf("Failed to convert to ITULAB\n");
return 1; return 1;
...@@ -532,7 +536,8 @@ int main(int argc, char *argv[]) ...@@ -532,7 +536,8 @@ int main(int argc, char *argv[])
bytes_per_row = (bits_per_pixel + 7)/8; bytes_per_row = (bits_per_pixel + 7)/8;
bytes_per_row *= w*samples_per_pixel; bytes_per_row *= w*samples_per_pixel;
totdata = h*bytes_per_row; totdata = h*bytes_per_row;
set_lab_illuminant(&lab_param, 0.9638f, 1.0f, 0.8245f); /* The default luminant is D50 */
set_lab_illuminant(&lab_param, 96.422f, 100.000f, 82.521f);
set_lab_gamut(&lab_param, 0, 100, -85, 85, -75, 125, FALSE); set_lab_gamut(&lab_param, 0, 100, -85, 85, -75, 125, FALSE);
#if 0 #if 0
start = rdtscll(); start = rdtscll();
...@@ -551,7 +556,7 @@ int main(int argc, char *argv[]) ...@@ -551,7 +556,7 @@ int main(int argc, char *argv[])
#else #else
data2 = malloc(totdata); data2 = malloc(totdata);
start = rdtscll(); start = rdtscll();
if (!t42_itulab_to_srgb(logging, &lab_param, data2, &off, data, off, &w, &h)) //if (!t42_itulab_jpeg_to_srgb(logging, &lab_param, data2, &off, data, off, &w, &h, &samples_per_pixel))
{ {
printf("Failed to convert from ITULAB\n"); printf("Failed to convert from ITULAB\n");
return 1; return 1;
......
差异被折叠。
...@@ -37,8 +37,12 @@ ...@@ -37,8 +37,12 @@
#include "udptl.h" #include "udptl.h"
#if !defined(FALSE)
#define FALSE 0 #define FALSE 0
#endif
#if !defined(TRUE)
#define TRUE (!FALSE) #define TRUE (!FALSE)
#endif
static int decode_length(const uint8_t *buf, int limit, int *len, int *pvalue) static int decode_length(const uint8_t *buf, int limit, int *len, int *pvalue)
{ {
...@@ -58,7 +62,7 @@ static int decode_length(const uint8_t *buf, int limit, int *len, int *pvalue) ...@@ -58,7 +62,7 @@ static int decode_length(const uint8_t *buf, int limit, int *len, int *pvalue)
return 0; return 0;
} }
*pvalue = (buf[(*len)++] & 0x3F) << 14; *pvalue = (buf[(*len)++] & 0x3F) << 14;
/* Indicate we have a fragment */ /* Indicate that we have a fragment */
return 1; return 1;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -66,11 +70,13 @@ static int decode_length(const uint8_t *buf, int limit, int *len, int *pvalue) ...@@ -66,11 +70,13 @@ static int decode_length(const uint8_t *buf, int limit, int *len, int *pvalue)
static int decode_open_type(const uint8_t *buf, int limit, int *len, const uint8_t **p_object, int *p_num_octets) static int decode_open_type(const uint8_t *buf, int limit, int *len, const uint8_t **p_object, int *p_num_octets)
{ {
int octet_cnt; int octet_cnt;
#if 0
int octet_idx; int octet_idx;
int stat; int stat;
const uint8_t **pbuf; const uint8_t **pbuf;
for (octet_idx = 0, *p_num_octets = 0; ; octet_idx += octet_cnt) *p_num_octets = 0;
for (octet_idx = 0; ; octet_idx += octet_cnt)
{ {
if ((stat = decode_length(buf, limit, len, &octet_cnt)) < 0) if ((stat = decode_length(buf, limit, len, &octet_cnt)) < 0)
return -1; return -1;
...@@ -89,6 +95,21 @@ static int decode_open_type(const uint8_t *buf, int limit, int *len, const uint8 ...@@ -89,6 +95,21 @@ static int decode_open_type(const uint8_t *buf, int limit, int *len, const uint8
if (stat == 0) if (stat == 0)
break; break;
} }
#else
/* We do not deal with fragments, so there is no point in looping through them. Just say that something
fragmented is bad. */
if (decode_length(buf, limit, len, &octet_cnt) != 0)
return -1;
*p_num_octets = octet_cnt;
if (octet_cnt > 0)
{
/* Make sure the buffer contains at least the number of bits requested */
if ((*len + octet_cnt) > limit)
return -1;
*p_object = &buf[*len];
*len += octet_cnt;
}
#endif
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
...@@ -153,7 +174,6 @@ static int encode_open_type(uint8_t *buf, int *len, const uint8_t *data, int num ...@@ -153,7 +174,6 @@ static int encode_open_type(uint8_t *buf, int *len, const uint8_t *data, int num
int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len) int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len)
{ {
int stat; int stat;
int stat2;
int i; int i;
int j; int j;
int k; int k;
...@@ -216,16 +236,16 @@ int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len) ...@@ -216,16 +236,16 @@ int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len)
total_count = 0; total_count = 0;
do do
{ {
if ((stat2 = decode_length(buf, len, &ptr, &count)) < 0) if ((stat = decode_length(buf, len, &ptr, &count)) < 0)
return -1; return -1;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
if ((stat = decode_open_type(buf, len, &ptr, &bufs[total_count + i], &lengths[total_count + i])) != 0) if (decode_open_type(buf, len, &ptr, &bufs[total_count + i], &lengths[total_count + i]) != 0)
return -1; return -1;
} }
total_count += count; total_count += count;
} }
while (stat2 > 0); while (stat > 0);
/* We should now be exactly at the end of the packet. If not, this is a fault. */ /* We should now be exactly at the end of the packet. If not, this is a fault. */
if (ptr != len) if (ptr != len)
return -1; return -1;
...@@ -246,7 +266,8 @@ int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len) ...@@ -246,7 +266,8 @@ int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len)
/* Save the new packet. Redundancy mode won't use this, but some systems will switch into /* Save the new packet. Redundancy mode won't use this, but some systems will switch into
FEC mode after sending some redundant packets, and this may then be important. */ FEC mode after sending some redundant packets, and this may then be important. */
x = (seq_no - i) & UDPTL_BUF_MASK; x = (seq_no - i) & UDPTL_BUF_MASK;
memcpy(s->rx[x].buf, bufs[i - 1], lengths[i - 1]); if (lengths[i - 1] > 0)
memcpy(s->rx[x].buf, bufs[i - 1], lengths[i - 1]);
s->rx[x].buf_len = lengths[i - 1]; s->rx[x].buf_len = lengths[i - 1];
s->rx[x].fec_len[0] = 0; s->rx[x].fec_len[0] = 0;
s->rx[x].fec_span = 0; s->rx[x].fec_span = 0;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论