t31.c File Reference

#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <time.h>
#include <memory.h>
#include <string.h>
#include <ctype.h>
#include <tgmath.h>
#include <math.h>
#include "floating_fudge.h"
#include <assert.h>
#include <tiffio.h>
#include "spandsp/telephony.h"
#include "spandsp/logging.h"
#include "spandsp/bit_operations.h"
#include "spandsp/bitstream.h"
#include "spandsp/dc_restore.h"
#include "spandsp/queue.h"
#include "spandsp/power_meter.h"
#include "spandsp/complex.h"
#include "spandsp/tone_detect.h"
#include "spandsp/tone_generate.h"
#include "spandsp/async.h"
#include "spandsp/crc.h"
#include "spandsp/hdlc.h"
#include "spandsp/silence_gen.h"
#include "spandsp/super_tone_rx.h"
#include "spandsp/fsk.h"
#include "spandsp/modem_connect_tones.h"
#include "spandsp/v8.h"
#include "spandsp/v29tx.h"
#include "spandsp/v29rx.h"
#include "spandsp/v27ter_tx.h"
#include "spandsp/v27ter_rx.h"
#include "spandsp/v17tx.h"
#include "spandsp/v17rx.h"
#include "spandsp/t4_rx.h"
#include "spandsp/t4_tx.h"
#include "spandsp/t30.h"
#include "spandsp/t30_logging.h"
#include "spandsp/t38_core.h"
#include "spandsp/at_interpreter.h"
#include "spandsp/fax_modems.h"
#include "spandsp/t31.h"
#include "spandsp/t30_fcf.h"
#include "spandsp/private/logging.h"
#include "spandsp/private/bitstream.h"
#include "spandsp/private/t38_core.h"
#include "spandsp/private/silence_gen.h"
#include "spandsp/private/fsk.h"
#include "spandsp/private/modem_connect_tones.h"
#include "spandsp/private/v8.h"
#include "spandsp/private/v17tx.h"
#include "spandsp/private/v17rx.h"
#include "spandsp/private/v27ter_tx.h"
#include "spandsp/private/v27ter_rx.h"
#include "spandsp/private/v29tx.h"
#include "spandsp/private/v29rx.h"
#include "spandsp/private/hdlc.h"
#include "spandsp/private/fax_modems.h"
#include "spandsp/private/at_interpreter.h"
#include "spandsp/private/t31.h"

Defines

#define MS_PER_TX_CHUNK   30
#define INDICATOR_TX_COUNT   3
#define DATA_TX_COUNT   1
#define DATA_END_TX_COUNT   3
#define DEFAULT_DTE_TIMEOUT   5
#define MAX_OCTETS_PER_UNPACED_CHUNK   300
#define MID_RX_TIMEOUT   15000
#define HDLC_FRAMING_OK_THRESHOLD   5

Typedefs

typedef const char *(* at_cmd_service_t )(t31_state_t *s, const char *cmd)

Enumerations

enum  { x03 = 0x03, x10 = 0x10, x1A = 0x1A }
enum  {
  DISBIT1 = 0x01, DISBIT2 = 0x02, DISBIT3 = 0x04, DISBIT4 = 0x08,
  DISBIT5 = 0x10, DISBIT6 = 0x20, DISBIT7 = 0x40, DISBIT8 = 0x80
}
enum  { T38_CHUNKING_MERGE_FCS_WITH_DATA = 0x0001, T38_CHUNKING_WHOLE_FRAMES = 0x0002, T38_CHUNKING_ALLOW_TEP_TIME = 0x0004 }
enum  {
  T38_TIMED_STEP_NONE = 0, T38_TIMED_STEP_NON_ECM_MODEM = 0x10, T38_TIMED_STEP_NON_ECM_MODEM_2 = 0x11, T38_TIMED_STEP_NON_ECM_MODEM_3 = 0x12,
  T38_TIMED_STEP_NON_ECM_MODEM_4 = 0x13, T38_TIMED_STEP_NON_ECM_MODEM_5 = 0x14, T38_TIMED_STEP_HDLC_MODEM = 0x20, T38_TIMED_STEP_HDLC_MODEM_2 = 0x21,
  T38_TIMED_STEP_HDLC_MODEM_3 = 0x22, T38_TIMED_STEP_HDLC_MODEM_4 = 0x23, T38_TIMED_STEP_HDLC_MODEM_5 = 0x24, T38_TIMED_STEP_FAKE_HDLC_MODEM = 0x30,
  T38_TIMED_STEP_FAKE_HDLC_MODEM_2 = 0x31, T38_TIMED_STEP_FAKE_HDLC_MODEM_3 = 0x32, T38_TIMED_STEP_FAKE_HDLC_MODEM_4 = 0x33, T38_TIMED_STEP_FAKE_HDLC_MODEM_5 = 0x34,
  T38_TIMED_STEP_CED = 0x40, T38_TIMED_STEP_CED_2 = 0x41, T38_TIMED_STEP_CED_3 = 0x42, T38_TIMED_STEP_CNG = 0x50,
  T38_TIMED_STEP_CNG_2 = 0x51, T38_TIMED_STEP_PAUSE = 0x60
}

Functions

int t31_t38_send_timeout (t31_state_t *s, int samples)
void t31_call_event (t31_state_t *s, int event)
int t31_at_rx (t31_state_t *s, const char *t, int len)
 SPAN_DECLARE_NONSTD (int)
 Get the next bit of a transmitted serial bit stream.
void t31_set_transmit_on_idle (t31_state_t *s, int transmit_on_idle)
 Select whether silent audio will be sent when transmit is idle.
void t31_set_tep_mode (t31_state_t *s, int use_tep)
 Select whether TEP mode will be used.
void t31_set_t38_config (t31_state_t *s, int without_pacing)
 Select whether T.38 data will be paced.
void t31_set_mode (t31_state_t *s, int t38_mode)
logging_state_tt31_get_logging_state (t31_state_t *s)
 Get a pointer to the logging context associated with a T.31 context.
t38_core_state_tt31_get_t38_core_state (t31_state_t *s)
t31_state_tt31_init (t31_state_t *s, at_tx_handler_t *at_tx_handler, void *at_tx_user_data, t31_modem_control_handler_t *modem_control_handler, void *modem_control_user_data, t38_tx_packet_handler_t *tx_t38_packet_handler, void *tx_t38_packet_user_data)
 Initialise a T.31 context.
int t31_release (t31_state_t *s)
 Release a T.31 context.
int t31_free (t31_state_t *s)
 Release a T.31 context.

Detailed Description


Define Documentation

#define DATA_END_TX_COUNT   3

The number of transmissions of terminating data IFP packets

Referenced by t31_set_t38_config(), and t38_terminal_set_config().

#define DATA_TX_COUNT   1

The number of transmissions of data IFP packets

Referenced by t31_set_t38_config(), and t38_terminal_set_config().

#define DEFAULT_DTE_TIMEOUT   5

The default DTE timeout, in seconds

Referenced by t31_init().

#define INDICATOR_TX_COUNT   3

The number of transmissions of indicator IFP packets

Referenced by t31_set_t38_config(), and t38_terminal_set_config().

#define MS_PER_TX_CHUNK   30

The default number of milliseconds per transmitted IFP when sending bulk T.38 data

Referenced by t31_set_t38_config().


Function Documentation

SPAN_DECLARE_NONSTD ( int   ) 

Get the next bit of a transmitted serial bit stream.

Get the next bit of data from a T.38 rate adapting non-ECM buffer context.

Get a bit of received non-ECM image data.

Get the next bit of a transmitted serial bit stream.

Parameters:
user_data An opaque point which must point to a transmitter context.
Returns:
the next bit, or PUTBIT_END_OF_DATA to indicate the data stream has ended.

Get the next bit of a transmitted serial bit stream.

Process a block of received V.8 audio samples.

Fake processing of a missing block of received V.29 modem audio samples.

Fake processing of a missing block of received V.27ter modem audio samples.

Generate a block of V.22bis modem audio samples.

Fake processing of a missing block of received V.22bis modem audio samples.

Process a block of received V.18 audio samples.

Fake processing of a missing block of received V.17 modem audio samples.

Generate a block of FAX audio samples.

Apply fake received audio processing.

Generate a block of T.31 modem audio samples.

Fake processing of a missing block of received T.31 modem audio samples.

Dummy receive fillin callback.

Dummy receive callback.

Process a block of samples through an instance of the modem connect tones detector.

Get the next sequence of bytes for transmission.

Get the next byte for transmission.

Fake processing of a missing block of received FSK modem audio samples.

Process a block of received FSK modem audio samples.

Apply T.30 transmit processing to generate a block of audio samples.

Apply fake T.30 receive processing when a block of audio samples is missing (e.g due to packet loss).

Parameters:
s The FAX context.
len The number of samples to fake.
Returns:
The number of samples unprocessed. This should only be non-zero if the software has reached the end of the FAX call.

Apply T.30 transmit processing to generate a block of audio samples.

Parameters:
s The FAX context.
amp The audio sample buffer.
max_len The number of samples to be generated.
Returns:
The number of samples actually generated. This will be zero when there is nothing to send.

Process a block of received FSK modem audio samples.

Parameters:
s The modem context.
amp The audio sample buffer.
len The number of samples in the buffer.
Returns:
The number of samples unprocessed.

Fake processing of a missing block of received FSK modem audio samples (e.g due to packet loss).

Parameters:
s The modem context.
len The number of samples to fake.
Returns:
The number of samples unprocessed.
Parameters:
s A pointer to an HDLC transmitter context.
Returns:
The next byte for transmission.
Parameters:
s A pointer to an HDLC transmitter context.
buf The buffer for the data.
max_len The number of bytes to get.
Returns:
The number of bytes actually got.
Parameters:
s The context.
amp An array of signal samples.
len The number of samples in the array.
Returns:
The number of unprocessed samples.

A dummy routine to use as a receive callback, when we aren't really trying to process what is received. It just absorbs and ignores the data.

Parameters:
user_data The context.
amp The signal.buffer
len The length of the signal buffer
Returns:
0.

A dummy routine to use as a receive fillin callback, when we aren't really trying to process what is received. It just absorbs and ignores the request.

Parameters:
user_data The context.
len The length of the signal buffer
Returns:
0.

Fake processing of a missing block of received T.31 modem audio samples (e.g due to packet loss).

Parameters:
s The T.31 modem context.
len The number of samples to fake.
Returns:
The number of samples unprocessed.

Generate a block of T.31 modem audio samples.

Parameters:
s The T.31 modem context.
amp The audio sample buffer.
max_len The number of samples to be generated.
Returns:
The number of samples actually generated.

Apply fake processing when a block of audio samples is missing (e.g due to packet loss).

Parameters:
s The T.38 context.
len The number of samples to fake.
Returns:
The number of samples unprocessed. This should only be non-zero if the software has reached the end of the FAX call.

Generate a block of FAX audio samples.

Parameters:
s The T.38 context.
amp The audio sample buffer.
max_len The number of samples to be generated.
Returns:
The number of samples actually generated.

Fake processing of a missing block of received V.17 modem audio samples. (e.g due to packet loss).

Parameters:
s The modem context.
len The number of samples to fake.
Returns:
The number of samples unprocessed.

Process a block of received V.18 audio samples.

Parameters:
s The V.18 context.
amp The audio sample buffer.
len The number of samples in the buffer.

Fake processing of a missing block of received V.22bis modem audio samples. (e.g due to packet loss).

Parameters:
s The modem context.
len The number of samples to fake.
Returns:
The number of samples unprocessed.

Generate a block of V.22bis modem audio samples.

Parameters:
s The modem context.
amp The audio sample buffer.
len The number of samples to be generated.
Returns:
The number of samples actually generated.

Fake processing of a missing block of received V.27ter modem audio samples. (e.g due to packet loss).

Parameters:
s The modem context.
len The number of samples to fake.
Returns:
The number of samples unprocessed.

Fake processing of a missing block of received V.29 modem audio samples. (e.g due to packet loss).

Parameters:
s The modem context.
len The number of samples to fake.
Returns:
The number of samples unprocessed.

Process a block of received V.8 audio samples.

Parameters:
s The V.8 context.
amp The audio sample buffer.
len The number of samples in the buffer.

Get the next bit of a transmitted serial bit stream.

Apply T.30 transmit processing to generate a block of audio samples.

Apply fake T.30 receive processing.

Apply T.30 receive processing to a block of audio samples.

Parameters:
s The FAX context.
amp The audio sample buffer.
len The number of samples in the buffer.
Returns:
The number of samples unprocessed. This should only be non-zero if the software has reached the end of the FAX call.

Apply fake T.30 receive processing when a block of audio samples is missing (e.g due to packet loss).

Parameters:
s The FAX context.
len The number of samples to fake.
Returns:
The number of samples unprocessed. This should only be non-zero if the software has reached the end of the FAX call.

Apply T.30 transmit processing to generate a block of audio samples.

Parameters:
s The FAX context.
amp The audio sample buffer.
max_len The number of samples to be generated.
Returns:
The number of samples actually generated. This will be zero when there is nothing to send.

Get the next bit of a transmitted serial bit stream.

Fake processing of a missing block of received FSK modem audio samples.

Process a block of received FSK modem audio samples.

Generate a block of FSK modem audio samples.

Parameters:
s The modem context.
amp The audio sample buffer.
len The number of samples to be generated.
Returns:
The number of samples actually generated.

Process a block of received FSK modem audio samples.

Parameters:
s The modem context.
amp The audio sample buffer.
len The number of samples in the buffer.
Returns:
The number of samples unprocessed.

Fake processing of a missing block of received FSK modem audio samples (e.g due to packet loss).

Parameters:
s The modem context.
len The number of samples to fake.
Returns:
The number of samples unprocessed.

Get the next bit of a transmitted serial bit stream.

Get the next sequence of bytes for transmission.

Get the next byte for transmission.

Parameters:
s A pointer to an HDLC transmitter context.
Returns:
The next bit for transmission.
Parameters:
s A pointer to an HDLC transmitter context.
Returns:
The next byte for transmission.
Parameters:
s A pointer to an HDLC transmitter context.
buf The buffer for the data.
max_len The number of bytes to get.
Returns:
The number of bytes actually got.

Get the next bit of a transmitted serial bit stream.

Process a block of samples through an instance of the modem connect tones detector.

Parameters:
s The context.
amp An array of signal samples.
len The number of samples to generate.
Returns:
The number of samples generated.
Parameters:
s The context.
amp An array of signal samples.
len The number of samples in the array.
Returns:
The number of unprocessed samples.

Get the next bit of a transmitted serial bit stream.

Dummy receive fillin callback.

Dummy receive callback.

Generate a block of silent audio samples.

Parameters:
s The silence generator context.
amp The audio sample buffer.
max_len The number of samples to be generated.
Returns:
The number of samples actually generated. This will be zero when there is nothing to send.

A dummy routine to use as a receive callback, when we aren't really trying to process what is received. It just absorbs and ignores the data.

Parameters:
user_data The context.
amp The signal.buffer
len The length of the signal buffer
Returns:
0.

A dummy routine to use as a receive fillin callback, when we aren't really trying to process what is received. It just absorbs and ignores the request.

Parameters:
user_data The context.
len The length of the signal buffer
Returns:
0.

Get the next bit of a transmitted serial bit stream.

Generate a block of T.31 modem audio samples.

Fake processing of a missing block of received T.31 modem audio samples.

Process a block of received T.31 modem audio samples.

Parameters:
s The T.31 modem context.
amp The audio sample buffer.
len The number of samples in the buffer.
Returns:
The number of samples unprocessed.

Fake processing of a missing block of received T.31 modem audio samples (e.g due to packet loss).

Parameters:
s The T.31 modem context.
len The number of samples to fake.
Returns:
The number of samples unprocessed.

Generate a block of T.31 modem audio samples.

Parameters:
s The T.31 modem context.
amp The audio sample buffer.
max_len The number of samples to be generated.
Returns:
The number of samples actually generated.

Get the next bit of a transmitted serial bit stream.

Generate a block of FAX audio samples.

Apply fake received audio processing.

Process a block of received FAX audio samples.

Parameters:
s The T.38 context.
amp The audio sample buffer.
len The number of samples in the buffer.
Returns:
The number of samples unprocessed.

Apply fake processing when a block of audio samples is missing (e.g due to packet loss).

Parameters:
s The T.38 context.
len The number of samples to fake.
Returns:
The number of samples unprocessed. This should only be non-zero if the software has reached the end of the FAX call.

Generate a block of FAX audio samples.

Parameters:
s The T.38 context.
amp The audio sample buffer.
max_len The number of samples to be generated.
Returns:
The number of samples actually generated.

Get the next bit of a transmitted serial bit stream.

Fake processing of a missing block of received V.17 modem audio samples.

Process a block of received V.17 modem audio samples.

Parameters:
s The modem context.
amp The audio sample buffer.
len The number of samples in the buffer.
Returns:
The number of samples unprocessed.

Fake processing of a missing block of received V.17 modem audio samples. (e.g due to packet loss).

Parameters:
s The modem context.
len The number of samples to fake.
Returns:
The number of samples unprocessed.

Get the next bit of a transmitted serial bit stream.

Generate a block of V.17 modem audio samples.

Parameters:
s The modem context.
amp The audio sample buffer.
len The number of samples to be generated.
Returns:
The number of samples actually generated.

Get the next bit of a transmitted serial bit stream.

Process a block of received V.18 audio samples.

Generate a block of V.18 audio samples.

Parameters:
s The V.18 context.
amp The audio sample buffer.
max_len The number of samples to be generated.
Returns:
The number of samples actually generated.

Process a block of received V.18 audio samples.

Parameters:
s The V.18 context.
amp The audio sample buffer.
len The number of samples in the buffer.

Get the next bit of a transmitted serial bit stream.

Generate a block of V.22bis modem audio samples.

Fake processing of a missing block of received V.22bis modem audio samples.

Process a block of received V.22bis modem audio samples.

Parameters:
s The modem context.
amp The audio sample buffer.
len The number of samples in the buffer.
Returns:
The number of samples unprocessed.

Fake processing of a missing block of received V.22bis modem audio samples. (e.g due to packet loss).

Parameters:
s The modem context.
len The number of samples to fake.
Returns:
The number of samples unprocessed.

Generate a block of V.22bis modem audio samples.

Parameters:
s The modem context.
amp The audio sample buffer.
len The number of samples to be generated.
Returns:
The number of samples actually generated.

Get the next bit of a transmitted serial bit stream.

Fake processing of a missing block of received V.27ter modem audio samples.

Process a block of received V.27ter modem audio samples.

Parameters:
s The modem context.
amp The audio sample buffer.
len The number of samples in the buffer.
Returns:
The number of samples unprocessed.

Fake processing of a missing block of received V.27ter modem audio samples. (e.g due to packet loss).

Parameters:
s The modem context.
len The number of samples to fake.
Returns:
The number of samples unprocessed.

Get the next bit of a transmitted serial bit stream.

Generate a block of V.27ter modem audio samples.

Parameters:
s The modem context.
amp The audio sample buffer.
len The number of samples to be generated.
Returns:
The number of samples actually generated.

Get the next bit of a transmitted serial bit stream.

Fake processing of a missing block of received V.29 modem audio samples.

Process a block of received V.29 modem audio samples.

Parameters:
s The modem context.
amp The audio sample buffer.
len The number of samples in the buffer.
Returns:
The number of samples unprocessed.

Fake processing of a missing block of received V.29 modem audio samples. (e.g due to packet loss).

Parameters:
s The modem context.
len The number of samples to fake.
Returns:
The number of samples unprocessed.

Get the next bit of a transmitted serial bit stream.

Generate a block of V.29 modem audio samples.

Parameters:
s The modem context.
amp The audio sample buffer.
len The number of samples to be generated.
Returns:
The number of samples actually generated.

Get the next bit of a transmitted serial bit stream.

Process a block of received V.8 audio samples.

Generate a block of V.8 audio samples.

Parameters:
s The V.8 context.
amp The audio sample buffer.
max_len The number of samples to be generated.
Returns:
The number of samples actually generated.

Process a block of received V.8 audio samples.

Parameters:
s The V.8 context.
amp The audio sample buffer.
len The number of samples in the buffer.
int t31_free ( t31_state_t s  ) 

Release a T.31 context.

Free a T.31 context.

Parameters:
s The T.31 context.
Returns:
0 for OK

References t31_release().

logging_state_t* t31_get_logging_state ( t31_state_t s  ) 

Get a pointer to the logging context associated with a T.31 context.

Get a pointer to the logging context associated with a T.31 context.

Parameters:
s The T.31 context.
Returns:
A pointer to the logging context, or NULL.
t31_state_t* t31_init ( t31_state_t s,
at_tx_handler_t *  at_tx_handler,
void *  at_tx_user_data,
t31_modem_control_handler_t *  modem_control_handler,
void *  modem_control_user_data,
t38_tx_packet_handler_t *  tx_t38_packet_handler,
void *  tx_t38_packet_user_data 
)

Initialise a T.31 context.

Initialise a T.31 context. This must be called before the first use of the context, to initialise its contents.

Parameters:
s The T.31 context.
at_tx_handler A callback routine to handle AT interpreter channel output.
at_tx_user_data An opaque pointer passed in called to at_tx_handler.
modem_control_handler A callback routine to handle control of the modem (off-hook, etc).
modem_control_user_data An opaque pointer passed in called to modem_control_handler.
tx_t38_packet_handler ???
tx_t38_packet_user_data ???
Returns:
A pointer to the T.31 context.

References at_init(), DEFAULT_DTE_TIMEOUT, MODEM_CONNECT_TONES_ANSAM_PR, power_meter_init(), power_meter_level_dbm0(), queue_init(), QUEUE_READ_ATOMIC, QUEUE_WRITE_ATOMIC, t31_set_t38_config(), and v8_init().

int t31_release ( t31_state_t s  ) 

Release a T.31 context.

Release a T.31 context.

Parameters:
s The T.31 context.
Returns:
0 for OK

Referenced by t31_free().

void t31_set_t38_config ( t31_state_t s,
int  without_pacing 
)

Select whether T.38 data will be paced.

Select whether T.38 data will be paced as it is transmitted.

Parameters:
s The T.31 modem context.
without_pacing TRUE if data is to be sent as fast as possible. FALSE if it is to be paced.

References DATA_END_TX_COUNT, DATA_TX_COUNT, INDICATOR_TX_COUNT, MS_PER_TX_CHUNK, T38_PACKET_CATEGORY_CONTROL_DATA, T38_PACKET_CATEGORY_CONTROL_DATA_END, T38_PACKET_CATEGORY_IMAGE_DATA, T38_PACKET_CATEGORY_IMAGE_DATA_END, T38_PACKET_CATEGORY_INDICATOR, and t38_set_redundancy_control().

Referenced by t31_init().

void t31_set_tep_mode ( t31_state_t s,
int  use_tep 
)

Select whether TEP mode will be used.

Select whether TEP mode will be used (or time allowed for it (when transmitting).

Parameters:
s The T.31 modem context.
use_tep TRUE if TEP is to be ised.
void t31_set_transmit_on_idle ( t31_state_t s,
int  transmit_on_idle 
)

Select whether silent audio will be sent when transmit is idle.

Select whether silent audio will be sent when transmit is idle.

Parameters:
s The T.31 modem context.
transmit_on_idle TRUE if silent audio should be output when the transmitter is idle. FALSE to transmit zero length audio when the transmitter is idle. The default behaviour is FALSE.

Generated on 25 Jan 2012 for spandsp by  doxygen 1.6.1