udptl.h

00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * udptl.c
00005  *
00006  * Written by Steve Underwood <steveu@coppice.org>
00007  *
00008  * Copyright (C) 2009 Steve Underwood
00009  *
00010  * All rights reserved.
00011  *
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License version 2, as
00014  * published by the Free Software Foundation.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024  */
00025 
00026 #if !defined(_SPANDSP_UDPTL_H_)
00027 #define _SPANDSP_UDPTL_H_
00028 
00029 #define LOCAL_FAX_MAX_DATAGRAM      400
00030 #define LOCAL_FAX_MAX_FEC_PACKETS   5
00031 
00032 #define UDPTL_BUF_MASK              15
00033 
00034 typedef int (udptl_rx_packet_handler_t) (void *user_data, const uint8_t msg[], int len, int seq_no);
00035 
00036 typedef struct
00037 {
00038     int buf_len;
00039     uint8_t buf[LOCAL_FAX_MAX_DATAGRAM];
00040 } udptl_fec_tx_buffer_t;
00041 
00042 typedef struct
00043 {
00044     int buf_len;
00045     uint8_t buf[LOCAL_FAX_MAX_DATAGRAM];
00046     int fec_len[LOCAL_FAX_MAX_FEC_PACKETS];
00047     uint8_t fec[LOCAL_FAX_MAX_FEC_PACKETS][LOCAL_FAX_MAX_DATAGRAM];
00048     int fec_span;
00049     int fec_entries;
00050 } udptl_fec_rx_buffer_t;
00051 
00052 struct udptl_state_s
00053 {
00054     udptl_rx_packet_handler_t *rx_packet_handler;
00055     void *user_data;
00056 
00057     /*! This option indicates the error correction scheme used in transmitted UDPTL
00058         packets. */
00059     int error_correction_scheme;
00060 
00061     /*! This option indicates the number of error correction entries transmitted in
00062         UDPTL packets. */
00063     int error_correction_entries;
00064 
00065     /*! This option indicates the span of the error correction entries in transmitted
00066         UDPTL packets (FEC only). */
00067     int error_correction_span;
00068 
00069     /*! This option indicates the maximum size of a datagram that can be accepted by
00070         the remote device. */
00071     int far_max_datagram_size;
00072 
00073     /*! This option indicates the maximum size of a datagram that we are prepared to
00074         accept. */
00075     int local_max_datagram_size;
00076 
00077     int verbose;
00078 
00079     int tx_seq_no;
00080     int rx_seq_no;
00081     int rx_expected_seq_no;
00082 
00083     udptl_fec_tx_buffer_t tx[UDPTL_BUF_MASK + 1];
00084     udptl_fec_rx_buffer_t rx[UDPTL_BUF_MASK + 1];
00085 };
00086 
00087 enum
00088 {
00089     UDPTL_ERROR_CORRECTION_NONE,
00090     UDPTL_ERROR_CORRECTION_FEC,
00091     UDPTL_ERROR_CORRECTION_REDUNDANCY
00092 };
00093 
00094 typedef struct udptl_state_s udptl_state_t;
00095 
00096 #if defined(__cplusplus)
00097 extern "C" {
00098 #endif
00099 
00100 /*! \brief Process an arriving UDPTL packet.
00101     \param s The UDPTL context.
00102     \param buf The UDPTL packet buffer.
00103     \param len The length of the packet.
00104     \return 0 for OK. */
00105 int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len);
00106 
00107 /*! \brief Construct a UDPTL packet, ready for transmission.
00108     \param s The UDPTL context.
00109     \param buf The UDPTL packet buffer.
00110     \param msg The primary packet.
00111     \param len The length of the primary packet.
00112     \return The length of the constructed UDPTL packet. */
00113 int udptl_build_packet(udptl_state_t *s, uint8_t buf[], const uint8_t msg[], int msg_len);
00114 
00115 /*! \brief Change the error correction settings of a UDPTL context.
00116     \param s The UDPTL context.
00117     \param ec_scheme One of the optional error correction schemes.
00118     \param span The packet span over which error correction should be applied.
00119     \param entries The number of error correction entries to include in packets.
00120     \return 0 for OK. */
00121 int udptl_set_error_correction(udptl_state_t *s, int ec_scheme, int span, int entries);
00122 
00123 /*! \brief Check the error correction settings of a UDPTL context.
00124     \param s The UDPTL context.
00125     \param ec_scheme One of the optional error correction schemes.
00126     \param span The packet span over which error correction is being applied.
00127     \param entries The number of error correction being included in packets.
00128     \return 0 for OK. */
00129 int udptl_get_error_correction(udptl_state_t *s, int *ec_scheme, int *span, int *entries);
00130 
00131 int udptl_set_local_max_datagram(udptl_state_t *s, int max_datagram);
00132 
00133 int udptl_get_local_max_datagram(udptl_state_t *s);
00134 
00135 int udptl_set_far_max_datagram(udptl_state_t *s, int max_datagram);
00136 
00137 int udptl_get_far_max_datagram(udptl_state_t *s);
00138 
00139 /*! \brief Initialise a UDPTL context.
00140     \param s The UDPTL context.
00141     \param ec_scheme One of the optional error correction schemes.
00142     \param span The packet span over which error correction should be applied.
00143     \param entries The number of error correction entries to include in packets.
00144     \param rx_packet_handler The callback function, used to report arriving IFP packets.
00145     \param user_data An opaque pointer supplied to rx_packet_handler.
00146     \return A pointer to the UDPTL context, or NULL if there was a problem. */
00147 udptl_state_t *udptl_init(udptl_state_t *s, int ec_scheme, int span, int entries, udptl_rx_packet_handler_t rx_packet_handler, void *user_data);
00148 
00149 /*! \brief Release a UDPTL context.
00150     \param s The UDPTL context.
00151     \return 0 for OK. */
00152 int udptl_release(udptl_state_t *s);
00153 
00154 #if defined(__cplusplus)
00155 }
00156 #endif
00157 #endif
00158 /*- End of file ------------------------------------------------------------*/

Generated on Fri Nov 18 15:02:25 2011 for spandsp by  doxygen 1.4.7