34 #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
36 #include <spandsp/version.h>
148 #define MAX_SAMPLES 240
156 #define WATCHDOG_TOTAL_TIMEOUT 30 * 60
157 #define WATCHDOG_STATE_TIMEOUT 5 * 60
171 if (level == SPAN_LOG_ERROR) {
173 }
else if (level == SPAN_LOG_WARNING) {
205 const char *local_ident;
206 const char *far_ident;
210 int pages_transferred;
212 ast_debug(1,
"Fax phase E handler. result=%d\n", result);
214 t30_get_transfer_statistics(f, &stat);
218 if (result != T30_ERR_OK) {
224 ast_log(
LOG_WARNING,
"Error transmitting fax. result=%d: %s.\n", result, t30_completion_code_to_str(result));
231 local_ident =
S_OR(t30_get_tx_ident(f),
"");
232 far_ident =
S_OR(t30_get_rx_ident(f),
"");
236 #if SPANDSP_RELEASE_DATE >= 20090220
237 pages_transferred = (s->
direction) ? stat.pages_tx : stat.pages_rx;
239 pages_transferred = stat.pages_transferred;
241 snprintf(buf,
sizeof(buf),
"%d", pages_transferred);
243 snprintf(buf,
sizeof(buf),
"%d", stat.y_resolution);
245 snprintf(buf,
sizeof(buf),
"%d", stat.bit_rate);
248 ast_debug(1,
"Fax transmitted successfully.\n");
249 ast_debug(1,
" Remote station ID: %s\n", far_ident);
250 ast_debug(1,
" Pages transferred: %d\n", pages_transferred);
251 ast_debug(1,
" Image resolution: %d x %d\n", stat.x_resolution, stat.y_resolution);
252 ast_debug(1,
" Transfer Rate: %d\n", stat.bit_rate);
255 s->
direction ?
"FaxSent" :
"FaxReceived",
259 "CallerIDName: %s\r\n"
260 "ConnectedLineNum: %s\r\n"
261 "ConnectedLineName: %s\r\n"
262 "RemoteStationID: %s\r\n"
263 "LocalStationID: %s\r\n"
264 "PagesTransferred: %d\r\n"
266 "TransferRate: %d\r\n"
290 span_log_set_level(state, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | level);
301 t30_set_tx_ident(state, x);
305 t30_set_tx_page_header_info(state, x);
311 t30_set_tx_file(state, s->
file_name, -1, -1);
313 t30_set_rx_file(state, s->
file_name, -1);
318 t30_set_ecm_capability(state, ecm);
319 t30_set_supported_compressions(state, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
333 fax_state_t *fax = (fax_state_t*) data;
348 if ((len = fax_tx(fax, buf, samples)) > 0) {
375 t30_state_t *t30state;
378 struct timeval now, start, state_change;
384 .fill_bit_removal = 1,
405 unsigned int timeout = 5000;
409 while (timeout > 0) {
430 (inf->
datalen ==
sizeof(t38_parameters))) {
457 #if SPANDSP_RELEASE_DATE >= 20080725
462 t30state = &fax.t30_state;
495 fax_set_transmit_on_idle(&fax,
TRUE);
507 ast_debug(1,
"Error waiting for a frame\n");
545 if (last_state != t30state->state) {
547 last_state = t30state->state;
556 ast_debug(1,
"T38 negotiated, finishing audio loop\n");
561 ast_debug(1,
"T38 request received, accepting\n");
574 ast_debug(1,
"Loop finished, res=%d\n", res);
585 t30_set_phase_e_handler(t30state, NULL, NULL);
588 t30_terminate(t30state);
609 t38_terminal_state_t
t38;
612 struct timeval now, start, state_change, last_frame;
613 t30_state_t *t30state;
614 t38_core_state_t *t38state;
616 #if SPANDSP_RELEASE_DATE >= 20080725
619 t38state = &t38.t38_fe.t38;
622 t30state = &t38.t30_state;
627 memset(&t38, 0,
sizeof(t38));
637 t38_set_fill_bit_removal(t38state,
TRUE);
640 t38_set_mmr_transcoding(t38state,
TRUE);
643 t38_set_jbig_transcoding(t38state,
TRUE);
658 now = start = state_change =
ast_tvnow();
664 ast_debug(1,
"Error waiting for a frame\n");
678 t38_terminal_send_timeout(&t38,
ast_tvdiff_us(now, last_frame) / (1000000 / 8000));
698 if (last_state != t30state->state) {
700 last_state = t30state->state;
714 ast_debug(1,
"Loop finished, res=%d\n", res);
719 t30_terminate(t30state);
720 t38_terminal_release(&t38);
732 unsigned int timeout = 5000;
736 while (timeout > 0) {
757 (inf->
datalen ==
sizeof(t38_parameters))) {
816 ast_log(
LOG_ERROR,
"Audio loop reports T38 switchover but t38state != T38_STATE_NEGOTIATED\n");
832 ast_debug(1,
"Transmission finished Ok\n");
845 char restore_digit_detect = 0;
870 if (strchr(
args.options,
'a'))
882 int dummy =
sizeof(restore_digit_detect);
887 if (restore_digit_detect) {
888 char new_digit_detect = 0;
895 char new_fax_detect = 0;
902 if (restore_digit_detect) {
914 char restore_digit_detect = 0;
939 if (strchr(
args.options,
'c'))
951 int dummy =
sizeof(restore_digit_detect);
956 if (restore_digit_detect) {
957 char new_digit_detect = 0;
964 char new_fax_detect = 0;
971 if (restore_digit_detect) {
996 span_set_message_handler(NULL);
static enum ast_t38_state ast_channel_get_t38_state(struct ast_channel *chan)
Retrieves the current T38 state of a channel.
union ast_frame_subclass subclass
Main Channel structure associated with a channel.
static int unload_module(void)
char * str
Subscriber phone number (Malloced)
struct ast_party_connected_line connected
Channel Connected Line ID information.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
static void set_ecm(t30_state_t *state, int ecm)
struct ast_party_caller caller
Channel Caller ID information.
struct ast_party_id id
Connected party ID.
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
struct ast_party_name name
Subscriber name.
static void set_local_info(t30_state_t *state, fax_session *s)
int ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block)
Checks the value of an option.
static const char app_sndfax_name[]
Convenient Signal Processing routines.
static int set_logging(logging_state_t *state)
int64_t ast_tvdiff_sec(struct timeval end, struct timeval start)
Computes the difference (in seconds) between two struct timeval instances.
static void dummy(char *unused,...)
static int load_module(void)
struct ast_control_t38_parameters t38parameters
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_OPTION_DIGIT_DETECT
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
enum ast_control_t38 request_response
static void phase_e_handler(t30_state_t *f, void *user_data, int result)
char * str
Subscriber name (Malloced)
int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen)
Indicates condition of channel, with payload.
ast_t38_state
Possible T38 states on channels.
static const char app_rcvfax_name[]
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
struct spandsp_fax_stats t38
int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block)
Sets an option on a channel.
int ast_unregister_application(const char *app)
Unregister an application.
static void * fax_generator_alloc(struct ast_channel *chan, void *params)
static void span_message(int level, const char *msg)
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
#define ast_manager_event(chan, category, event, contents,...)
struct ast_channel * chan
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
struct ast_party_id id
Caller party ID.
int ast_set_write_format(struct ast_channel *chan, format_t format)
Sets write format on channel chan Set write format for channel to whichever component of "format" is ...
static void set_file(t30_state_t *state, fax_session *s)
int ast_set_read_format(struct ast_channel *chan, format_t format)
Sets read format on channel chan Set read format for channel to whichever component of "format" is be...
#define ast_debug(level,...)
Log a DEBUG message.
unsigned int transcoding_mmr
General Asterisk PBX channel definitions.
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
static int disable_t38(struct ast_channel *chan)
static force_inline int attribute_pure ast_strlen_zero(const char *s)
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
static int rcvfax_exec(struct ast_channel *chan, const char *data)
Core PBX routines and definitions.
#define AST_OPTION_FAX_DETECT
static int sndfax_exec(struct ast_channel *chan, const char *data)
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
#define ast_strdupa(s)
duplicate a string in memory from the stack
static int transmit_t38(fax_session *s)
static struct ast_generator generator
unsigned int fill_bit_removal
static int transmit_audio(fax_session *s)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
enum ast_channel_state _state
const ast_string_field name
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
void *(* alloc)(struct ast_channel *chan, void *params)
static void parse(struct mgcp_request *req)
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
static int fax_generator_generate(struct ast_channel *chan, void *data, int len, int samples)
Support for logging to various files, console and syslog Configuration in file logger.conf.
int(* generate)(struct ast_channel *chan, void *data, int len, int samples)
unsigned int transcoding_jbig
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
void ast_deactivate_generator(struct ast_channel *chan)
#define AST_FORMAT_SLINEAR
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
int ast_answer(struct ast_channel *chan)
Answer a channel.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
enum ast_t38_state t38state
Data structure associated with a single frame of data.
static int transmit(fax_session *s)
static int t38_tx_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count)
int64_t ast_tvdiff_us(struct timeval end, struct timeval start)
Computes the difference (in microseconds) between two struct timeval instances.
#define AST_APP_ARG(name)
Define an application argument.
enum ast_frame_type frametype
unsigned char valid
TRUE if the name information is valid/present.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define WATCHDOG_STATE_TIMEOUT
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
union ast_frame::@172 data
unsigned char valid
TRUE if the number information is valid/present.
char exten[AST_MAX_EXTENSION]
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
#define WATCHDOG_TOTAL_TIMEOUT
struct ast_party_number number
Subscriber phone number.