24 #define ASTMM_LIBC ASTMM_IGNORE 35 #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES 37 #include <spandsp/version.h> 151 #define MAX_SAMPLES 240 159 #define WATCHDOG_TOTAL_TIMEOUT 30 * 60 160 #define WATCHDOG_STATE_TIMEOUT 5 * 60 174 if (level == SPAN_LOG_ERROR) {
176 }
else if (level == SPAN_LOG_WARNING) {
211 const char *local_ident;
212 const char *far_ident;
216 int pages_transferred;
218 ast_debug(1,
"Fax phase E handler. result=%d\n", result);
220 t30_get_transfer_statistics(f, &stat);
224 if (result != T30_ERR_OK) {
230 ast_log(
LOG_WARNING,
"Error transmitting fax. result=%d: %s.\n", result, t30_completion_code_to_str(result));
237 local_ident =
S_OR(t30_get_tx_ident(f),
"");
238 far_ident =
S_OR(t30_get_rx_ident(f),
"");
242 #if SPANDSP_RELEASE_DATE >= 20090220 243 pages_transferred = (s->
direction) ? stat.pages_tx : stat.pages_rx;
245 pages_transferred = stat.pages_transferred;
247 snprintf(buf,
sizeof(buf),
"%d", pages_transferred);
249 snprintf(buf,
sizeof(buf),
"%d", stat.y_resolution);
251 snprintf(buf,
sizeof(buf),
"%d", stat.bit_rate);
254 ast_debug(1,
"Fax transmitted successfully.\n");
255 ast_debug(1,
" Remote station ID: %s\n", far_ident);
256 ast_debug(1,
" Pages transferred: %d\n", pages_transferred);
257 ast_debug(1,
" Image resolution: %d x %d\n", stat.x_resolution, stat.y_resolution);
258 ast_debug(1,
" Transfer Rate: %d\n", stat.bit_rate);
261 if (!json_filenames) {
265 json_object =
ast_json_pack(
"{s: s, s: s, s: s, s: i, s: i, s: i, s: o}",
266 "type", s->
direction ?
"send" :
"receive",
269 "fax_pages", pages_transferred,
270 "fax_resolution", stat.y_resolution,
271 "fax_bitrate", stat.bit_rate,
272 "filenames", json_filenames);
288 span_log_set_level(state, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | level);
299 t30_set_tx_ident(state, x);
303 t30_set_tx_page_header_info(state, x);
309 t30_set_tx_file(state, s->
file_name, -1, -1);
311 t30_set_rx_file(state, s->
file_name, -1);
316 t30_set_ecm_capability(state, ecm);
317 t30_set_supported_compressions(state, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
331 fax_state_t *fax = (fax_state_t*) data;
346 if ((len = fax_tx(fax, buf, samples)) > 0) {
373 t30_state_t *t30state;
376 struct timeval now, start, state_change;
382 .fill_bit_removal = 1,
407 while (timeout > 0) {
428 (inf->
datalen ==
sizeof(t38_parameters))) {
455 #if SPANDSP_RELEASE_DATE >= 20080725 460 t30state = &fax.t30_state;
489 fax_set_transmit_on_idle(&fax,
TRUE);
501 ast_debug(1,
"Error waiting for a frame\n");
540 if (last_state != t30state->state) {
542 last_state = t30state->state;
551 ast_debug(1,
"T38 negotiated, finishing audio loop\n");
556 ast_debug(1,
"T38 request received, accepting\n");
569 ast_debug(1,
"Loop finished, res=%d\n", res);
580 t30_set_phase_e_handler(t30state,
NULL,
NULL);
583 t30_terminate(t30state);
587 if (original_write_fmt) {
590 ao2_ref(original_write_fmt, -1);
593 if (original_read_fmt) {
596 ao2_ref(original_read_fmt, -1);
606 t38_terminal_state_t
t38;
609 struct timeval now, start, state_change, last_frame;
610 t30_state_t *t30state;
613 #if SPANDSP_RELEASE_DATE >= 20080725 616 t38state = &t38.t38_fe.t38;
619 t30state = &t38.t30_state;
624 memset(&t38, 0,
sizeof(t38));
634 t38_set_fill_bit_removal(t38state,
TRUE);
637 t38_set_mmr_transcoding(t38state,
TRUE);
640 t38_set_jbig_transcoding(t38state,
TRUE);
655 now = start = state_change =
ast_tvnow();
661 ast_debug(1,
"Error waiting for a frame\n");
675 t38_terminal_send_timeout(&t38,
ast_tvdiff_us(now, last_frame) / (1000000 / 8000));
695 if (last_state != t30state->state) {
697 last_state = t30state->state;
711 ast_debug(1,
"Loop finished, res=%d\n", res);
716 t30_terminate(t30state);
717 t38_terminal_release(&t38);
733 while (timeout > 0) {
754 (inf->
datalen ==
sizeof(t38_parameters))) {
813 ast_log(
LOG_ERROR,
"Audio loop reports T38 switchover but t38state != T38_STATE_NEGOTIATED\n");
829 ast_debug(1,
"Transmission finished Ok\n");
842 char restore_digit_detect = 0;
867 if (strchr(
args.options,
'a'))
879 int dummy =
sizeof(restore_digit_detect);
884 if (restore_digit_detect) {
885 char new_digit_detect = 0;
892 char new_fax_detect = 0;
899 if (restore_digit_detect) {
911 char restore_digit_detect = 0;
936 if (strchr(
args.options,
'c'))
948 int dummy =
sizeof(restore_digit_detect);
953 if (restore_digit_detect) {
954 char new_digit_detect = 0;
961 char new_fax_detect = 0;
968 if (restore_digit_detect) {
993 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.
Main Channel structure associated with a channel.
static int unload_module(void)
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
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_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
void *(* alloc)(struct ast_channel *chan, void *params)
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
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.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
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
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)
ast_channel_state
ast_channel states
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().
t38state
T38 States for a call.
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.
struct ast_frame_subclass subclass
#define ast_strlen_zero(foo)
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
struct ast_channel * chan
static void set_file(t30_state_t *state, fax_session *s)
#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.
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
static int disable_t38(struct ast_channel *chan)
static struct ast_mansession session
#define ao2_ref(o, delta)
#define ast_strdupa(s)
duplicate a string in memory from the stack
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
static int rcvfax_exec(struct ast_channel *chan, const char *data)
Core PBX routines and definitions.
static int sndfax_exec(struct ast_channel *chan, const char *data)
const char * ast_channel_uniqueid(const struct ast_channel *chan)
struct stasis_topic * ast_channel_topic(struct ast_channel *chan)
A topic which publishes the events for a particular channel.
#define AST_OPTION_DIGIT_DETECT
static int transmit_t38(fax_session *s)
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
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)
static void parse(struct mgcp_request *req)
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
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.
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
struct stasis_message * ast_channel_blob_create_from_cache(const char *uniqueid, struct stasis_message_type *type, struct ast_json *blob)
Create a ast_channel_blob message, pulling channel state from the cache.
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_OPTION_FAX_DETECT
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...
const char * ast_channel_name(const struct ast_channel *chan)
int ast_answer(struct ast_channel *chan)
Answer a channel.
enum ast_t38_state t38state
Data structure associated with a single frame of data.
static int transmit(fax_session *s)
Abstract JSON element (object, array, string, int, ...).
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.
union ast_frame::@263 data
enum ast_frame_type frametype
struct ast_format * format
#define WATCHDOG_STATE_TIMEOUT
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
struct stasis_message_type * ast_channel_fax_type(void)
Message type for a fax operation.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define AST_JSON_UTF8_VALIDATE(str)
Check str for UTF-8 and replace with an empty string if fails the check.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
#define AST_APP_ARG(name)
Define an application argument.
#define WATCHDOG_TOTAL_TIMEOUT