#include "asterisk.h"
#include "asterisk/_private.h"
#include <sys/time.h>
#include <signal.h>
#include <math.h>
#include "asterisk/paths.h"
#include "asterisk/pbx.h"
#include "asterisk/frame.h"
#include "asterisk/mod_format.h"
#include "asterisk/sched.h"
#include "asterisk/channel.h"
#include "asterisk/musiconhold.h"
#include "asterisk/say.h"
#include "asterisk/file.h"
#include "asterisk/cli.h"
#include "asterisk/translate.h"
#include "asterisk/manager.h"
#include "asterisk/chanvars.h"
#include "asterisk/linkedlists.h"
#include "asterisk/indications.h"
#include "asterisk/monitor.h"
#include "asterisk/causes.h"
#include "asterisk/callerid.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"
#include "asterisk/transcap.h"
#include "asterisk/devicestate.h"
#include "asterisk/sha1.h"
#include "asterisk/threadstorage.h"
#include "asterisk/slinfactory.h"
#include "asterisk/audiohook.h"
#include "asterisk/timing.h"
Go to the source code of this file.
Data Structures | |
struct | ast_cause |
map AST_CAUSE's to readable string representations More... | |
struct | ast_epoll_data |
struct | ast_silence_generator |
struct | backends |
the list of registered channel types More... | |
struct | chanlist |
List of channel drivers. More... | |
struct | channels |
the list of channels we have. Note that the lock for this list is used for both the channels list and the backends list. More... | |
struct | tonepair_def |
struct | tonepair_state |
Defines | |
#define | AST_DEFAULT_EMULATE_DTMF_DURATION 100 |
#define | AST_MIN_DTMF_DURATION 80 |
#define | AST_MIN_DTMF_GAP 45 |
#define | FORMAT "%-10.10s %-40.40s %-12.12s %-12.12s %-12.12s\n" |
#define | STATE2STR_BUFSIZE 32 |
Functions | |
int | __ast_answer (struct ast_channel *chan, unsigned int delay, int cdr_answer) |
Answer a channel, with a selectable delay before returning. | |
ast_channel * | __ast_channel_alloc (int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const int amaflag, const char *file, int line, const char *function, const char *name_fmt,...) |
Create a channel structure. | |
static struct ast_channel *attribute_malloc | __ast_channel_alloc_ap (int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const int amaflag, const char *file, int line, const char *function, const char *name_fmt, va_list ap1, va_list ap2) |
Create a new channel structure. | |
static int | __ast_queue_frame (struct ast_channel *chan, struct ast_frame *fin, int head, struct ast_frame *after) |
static struct ast_frame * | __ast_read (struct ast_channel *chan, int dropaudio) |
ast_channel * | __ast_request_and_dial (const char *type, int format, void *data, int timeout, int *outstate, const char *cid_num, const char *cid_name, struct outgoing_helper *oh) |
Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it. | |
static void | __init_state2str_threadbuf (void) |
int | ast_activate_generator (struct ast_channel *chan, struct ast_generator *gen, void *params) |
int | ast_active_channels (void) |
returns number of active/allocated channels | |
int | ast_answer (struct ast_channel *chan) |
Answer a channel. | |
void | ast_begin_shutdown (int hangup) |
Initiate system shutdown. | |
int | ast_best_codec (int fmts) |
Pick the best audio codec. | |
ast_channel * | ast_bridged_channel (struct ast_channel *chan) |
Find bridged channel. | |
int | ast_call (struct ast_channel *chan, char *addr, int timeout) |
Make a call. | |
ast_channel * | ast_call_forward (struct ast_channel *caller, struct ast_channel *orig, int *timeout, int format, struct outgoing_helper *oh, int *outstate) |
Forwards a call to a new channel specified by the original channel's call_forward str. If possible, the new forwarded channel is created and returned while the original one is terminated. | |
void | ast_cancel_shutdown (void) |
Cancel a shutdown in progress. | |
const char * | ast_cause2str (int cause) |
Gives the string form of a given hangup cause. | |
void | ast_change_name (struct ast_channel *chan, char *newname) |
Change channel name. | |
ast_channel * | ast_channel_alloc (int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const int amaflag, const char *name_fmt,...) |
enum ast_bridge_result | ast_channel_bridge (struct ast_channel *c0, struct ast_channel *c1, struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc) |
Bridge two channels together. | |
int | ast_channel_cmpwhentohangup (struct ast_channel *chan, time_t offset) |
Compare a offset with the settings of when to hang a channel up. | |
int | ast_channel_cmpwhentohangup_tv (struct ast_channel *chan, struct timeval offset) |
Compare a offset with the settings of when to hang a channel up. | |
int | ast_channel_datastore_add (struct ast_channel *chan, struct ast_datastore *datastore) |
Add a datastore to a channel. | |
ast_datastore * | ast_channel_datastore_alloc (const struct ast_datastore_info *info, const char *uid) |
Create a channel data store object. | |
ast_datastore * | ast_channel_datastore_find (struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid) |
Find a datastore on a channel. | |
int | ast_channel_datastore_free (struct ast_datastore *datastore) |
Free a channel data store object. | |
int | ast_channel_datastore_inherit (struct ast_channel *from, struct ast_channel *to) |
Inherit datastores from a parent to a child. | |
int | ast_channel_datastore_remove (struct ast_channel *chan, struct ast_datastore *datastore) |
Remove a datastore from a channel. | |
int | ast_channel_defer_dtmf (struct ast_channel *chan) |
Set defer DTMF flag on channel. | |
int | ast_channel_early_bridge (struct ast_channel *c0, struct ast_channel *c1) |
Bridge two channels together (early). | |
void | ast_channel_free (struct ast_channel *chan) |
Free a channel structure. | |
void | ast_channel_inherit_variables (const struct ast_channel *parent, struct ast_channel *child) |
Inherits channel variable from parent to child channel. | |
int | ast_channel_make_compatible (struct ast_channel *chan, struct ast_channel *peer) |
Makes two channel formats compatible. | |
static int | ast_channel_make_compatible_helper (struct ast_channel *from, struct ast_channel *to) |
Set up translation from one channel to another. | |
int | ast_channel_masquerade (struct ast_channel *original, struct ast_channel *clonechan) |
Weird function made for call transfers. | |
int | ast_channel_queryoption (struct ast_channel *chan, int option, void *data, int *datalen, int block) |
const char * | ast_channel_reason2str (int reason) |
return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument | |
int | ast_channel_register (const struct ast_channel_tech *tech) |
Register a channel technology (a new channel driver) Called by a channel module to register the kind of channels it supports. | |
int | ast_channel_sendhtml (struct ast_channel *chan, int subclass, const char *data, int datalen) |
int | ast_channel_sendurl (struct ast_channel *chan, const char *url) |
void | ast_channel_set_fd (struct ast_channel *chan, int which, int fd) |
int | ast_channel_setoption (struct ast_channel *chan, int option, void *data, int datalen, int block) |
Sets an option on a channel. | |
void | ast_channel_setwhentohangup (struct ast_channel *chan, time_t offset) |
Set when to hang a channel up. | |
void | ast_channel_setwhentohangup_tv (struct ast_channel *chan, struct timeval offset) |
Set when to hang a channel up. | |
ast_silence_generator * | ast_channel_start_silence_generator (struct ast_channel *chan) |
Starts a silence generator on the given channel. | |
void | ast_channel_stop_silence_generator (struct ast_channel *chan, struct ast_silence_generator *state) |
Stops a previously-started silence generator on the given channel. | |
int | ast_channel_supports_html (struct ast_channel *chan) |
void | ast_channel_undefer_dtmf (struct ast_channel *chan) |
Unset defer DTMF flag on channel. | |
void | ast_channel_unregister (const struct ast_channel_tech *tech) |
Unregister a channel technology. | |
ast_channel * | ast_channel_walk_locked (const struct ast_channel *prev) |
Browse channels in use Browse the channels currently in use. | |
void | ast_channels_init (void) |
ast_variable * | ast_channeltype_list (void) |
return an ast_variable list of channeltypes | |
int | ast_check_hangup (struct ast_channel *chan) |
Check to see if a channel is needing hang up. | |
static int | ast_check_hangup_locked (struct ast_channel *chan) |
void | ast_deactivate_generator (struct ast_channel *chan) |
int | ast_do_masquerade (struct ast_channel *original) |
Start masquerading a channel XXX This is a seriously whacked out operation. We're essentially putting the guts of the clone channel into the original channel. Start by killing off the original channel's backend. I'm not sure we're going to keep this function, because while the features are nice, the cost is very high in terms of pure nastiness. XXX. | |
static enum ast_bridge_result | ast_generic_bridge (struct ast_channel *c0, struct ast_channel *c1, struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc, struct timeval bridge_end) |
ast_channel * | ast_get_channel_by_exten_locked (const char *exten, const char *context) |
Get channel by exten (and optionally context) and lock it. | |
ast_channel * | ast_get_channel_by_name_locked (const char *name) |
Get channel by name or uniqueid (locks channel). | |
ast_channel * | ast_get_channel_by_name_prefix_locked (const char *name, const int namelen) |
Get channel by name or uniqueid prefix (locks channel). | |
ast_channel_tech * | ast_get_channel_tech (const char *name) |
Get a channel technology structure by name. | |
ast_group_t | ast_get_group (const char *s) |
int | ast_hangup (struct ast_channel *chan) |
Hang up a channel. | |
int | ast_indicate (struct ast_channel *chan, int condition) |
Indicates condition of channel. | |
int | ast_indicate_data (struct ast_channel *chan, int _condition, const void *data, size_t datalen) |
Indicates condition of channel, with payload. | |
void | ast_install_music_functions (int(*start_ptr)(struct ast_channel *, const char *, const char *), void(*stop_ptr)(struct ast_channel *), void(*cleanup_ptr)(struct ast_channel *)) |
int | ast_internal_timing_enabled (struct ast_channel *chan) |
Check if the channel can run in internal timing mode. | |
void | ast_moh_cleanup (struct ast_channel *chan) |
int | ast_moh_start (struct ast_channel *chan, const char *mclass, const char *interpclass) |
Turn on music on hold on a given channel. | |
void | ast_moh_stop (struct ast_channel *chan) |
Turn off music on hold on a given channel. | |
void | ast_poll_channel_add (struct ast_channel *chan0, struct ast_channel *chan1) |
void | ast_poll_channel_del (struct ast_channel *chan0, struct ast_channel *chan1) |
char * | ast_print_group (char *buf, int buflen, ast_group_t group) |
print call- and pickup groups into buffer | |
int | ast_prod (struct ast_channel *chan) |
Send empty audio to prime a channel driver. | |
int | ast_queue_control (struct ast_channel *chan, enum ast_control_frame_type control) |
Queue a control frame with payload. | |
int | ast_queue_control_data (struct ast_channel *chan, enum ast_control_frame_type control, const void *data, size_t datalen) |
Queue a control frame with payload. | |
int | ast_queue_frame (struct ast_channel *chan, struct ast_frame *fin) |
Queue one or more frames to a channel's frame queue. | |
int | ast_queue_frame_head (struct ast_channel *chan, struct ast_frame *fin) |
Queue one or more frames to the head of a channel's frame queue. | |
int | ast_queue_hangup (struct ast_channel *chan) |
Queue a hangup frame. | |
int | ast_queue_hangup_with_cause (struct ast_channel *chan, int cause) |
Queue a hangup frame with hangupcause set. | |
int | ast_raw_answer (struct ast_channel *chan, int cdr_answer) |
Answer a channel. | |
ast_frame * | ast_read (struct ast_channel *chan) |
Reads a frame. | |
static void | ast_read_generator_actions (struct ast_channel *chan, struct ast_frame *f) |
ast_frame * | ast_read_noaudio (struct ast_channel *chan) |
Reads a frame, returning AST_FRAME_NULL frame if audio. | |
int | ast_readstring (struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders) |
int | ast_readstring_full (struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders, int audiofd, int ctrlfd) |
int | ast_recvchar (struct ast_channel *chan, int timeout) |
Receives a text character from a channel. | |
char * | ast_recvtext (struct ast_channel *chan, int timeout) |
Receives a text string from a channel Read a string of text from a channel. | |
ast_channel * | ast_request (const char *type, int format, void *data, int *cause) |
Requests a channel. | |
ast_channel * | ast_request_and_dial (const char *type, int format, void *data, int timeout, int *outstate, const char *cidnum, const char *cidname) |
Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it. | |
int | ast_safe_sleep (struct ast_channel *chan, int ms) |
Wait for a specified amount of time, looking for hangups. | |
int | ast_safe_sleep_conditional (struct ast_channel *chan, int ms, int(*cond)(void *), void *data) |
Wait for a specified amount of time, looking for hangups and a condition argument. | |
int | ast_say_character_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang) |
int | ast_say_digit_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang) |
int | ast_say_digits (struct ast_channel *chan, int num, const char *ints, const char *lang) |
int | ast_say_digits_full (struct ast_channel *chan, int num, const char *ints, const char *lang, int audiofd, int ctrlfd) |
int | ast_say_enumeration (struct ast_channel *chan, int num, const char *ints, const char *language, const char *options) |
int | ast_say_number (struct ast_channel *chan, int num, const char *ints, const char *language, const char *options) |
int | ast_say_phonetic_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang) |
int | ast_senddigit (struct ast_channel *chan, char digit, unsigned int duration) |
Send a DTMF digit to a channel Send a DTMF digit to a channel. | |
int | ast_senddigit_begin (struct ast_channel *chan, char digit) |
Send a DTMF digit to a channel Send a DTMF digit to a channel. | |
int | ast_senddigit_end (struct ast_channel *chan, char digit, unsigned int duration) |
Send a DTMF digit to a channel. | |
int | ast_sendtext (struct ast_channel *chan, const char *text) |
Sends text to a channel. | |
void | ast_set_callerid (struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani) |
Set caller ID number, name and ANI. | |
int | ast_set_read_format (struct ast_channel *chan, int fmt) |
Sets read format on channel chan Set read format for channel to whichever component of "format" is best. | |
void | ast_set_variables (struct ast_channel *chan, struct ast_variable *vars) |
adds a list of channel variables to a channel | |
int | ast_set_write_format (struct ast_channel *chan, int fmt) |
Sets write format on channel chan Set write format for channel to whichever component of "format" is best. | |
int | ast_setstate (struct ast_channel *chan, enum ast_channel_state state) |
Change the state of a channel. | |
int | ast_settimeout (struct ast_channel *c, unsigned int rate, int(*func)(const void *data), void *data) |
Enable or disable timer ticks for a channel. | |
int | ast_shutting_down (void) |
Returns non-zero if Asterisk is being shut down. | |
int | ast_softhangup (struct ast_channel *chan, int cause) |
Softly hangup up a channel. | |
int | ast_softhangup_nolock (struct ast_channel *chan, int cause) |
Softly hangup up a channel (no channel lock). | |
const char * | ast_state2str (enum ast_channel_state state) |
Gives the string form of a given channel state. | |
int | ast_str2cause (const char *name) |
Convert a symbolic hangup cause to number. | |
int | ast_tonepair (struct ast_channel *chan, int freq1, int freq2, int duration, int vol) |
int | ast_tonepair_start (struct ast_channel *chan, int freq1, int freq2, int duration, int vol) |
void | ast_tonepair_stop (struct ast_channel *chan) |
int | ast_transfer (struct ast_channel *chan, char *dest) |
Transfer a channel (if supported). Returns -1 on error, 0 if not supported and 1 if supported and requested. | |
char * | ast_transfercapability2str (int transfercapability) |
Gives the string form of a given transfer capability. | |
void | ast_uninstall_music_functions (void) |
int | ast_waitfor (struct ast_channel *c, int ms) |
Wait for input on a channel. | |
ast_channel * | ast_waitfor_n (struct ast_channel **c, int n, int *ms) |
Waits for input on a group of channels Wait for input on an array of channels for a given # of milliseconds. | |
int | ast_waitfor_n_fd (int *fds, int n, int *ms, int *exception) |
Waits for input on an fd This version works on fd's only. Be careful with it. | |
ast_channel * | ast_waitfor_nandfds (struct ast_channel **c, int n, int *fds, int nfds, int *exception, int *outfd, int *ms) |
Waits for activity on a group of channels. | |
int | ast_waitfordigit (struct ast_channel *c, int ms) |
Waits for a digit. | |
int | ast_waitfordigit_full (struct ast_channel *c, int ms, int audiofd, int cmdfd) |
Wait for a digit Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading. | |
ast_channel * | ast_walk_channel_by_exten_locked (const struct ast_channel *chan, const char *exten, const char *context) |
Get next channel by exten (and optionally context) and lock it. | |
ast_channel * | ast_walk_channel_by_name_prefix_locked (const struct ast_channel *chan, const char *name, const int namelen) |
Get channel by name or uniqueid prefix (locks channel). | |
int | ast_write (struct ast_channel *chan, struct ast_frame *fr) |
Write a frame to a channel This function writes the given frame to the indicated channel. | |
int | ast_write_video (struct ast_channel *chan, struct ast_frame *fr) |
Write video frame to a channel This function writes the given frame to the indicated channel. | |
static void | bridge_play_sounds (struct ast_channel *c0, struct ast_channel *c1) |
static void | bridge_playfile (struct ast_channel *chan, struct ast_channel *peer, const char *sound, int remain) |
static int | calc_monitor_jump (int samples, int sample_rate, int seek_rate) |
calculates the number of samples to jump forward with in a monitor stream. | |
static struct ast_channel * | channel_find_locked (const struct ast_channel *prev, const char *name, const int namelen, const char *context, const char *exten) |
Helper function to find channels. | |
const char * | channelreloadreason2txt (enum channelreloadreason reason) |
Convert enum channelreloadreason to text string for manager event. | |
static void | clone_variables (struct ast_channel *original, struct ast_channel *clonechan) |
Clone channel variables from 'clone' channel into 'original' channel. | |
static char * | complete_channeltypes (struct ast_cli_args *a) |
static void | free_cid (struct ast_callerid *cid) |
static void | free_translation (struct ast_channel *clonechan) |
static int | generator_force (const void *data) |
static void | handle_cause (int cause, int *outstate) |
static char * | handle_cli_core_show_channeltype (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
Show details about a channel driver - CLI command. | |
static char * | handle_cli_core_show_channeltypes (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
Show channel types - CLI command. | |
static int attribute_const | is_visible_indication (enum ast_control_frame_type condition) |
static void | manager_bridge_event (int onoff, int type, struct ast_channel *c0, struct ast_channel *c1) |
Send manager event for bridge link and unlink events. | |
static void | queue_dtmf_readq (struct ast_channel *chan, struct ast_frame *f) |
static void | report_new_callerid (const struct ast_channel *chan) |
static void | send_dtmf_event (const struct ast_channel *chan, const char *direction, const char digit, const char *begin, const char *end) |
static int | set_format (struct ast_channel *chan, int fmt, int *rawformat, int *format, struct ast_trans_pvt **trans, const int direction) |
static int | should_skip_dtmf (struct ast_channel *chan) |
Determine whether or not we should ignore DTMF in the readq. | |
static void * | silence_generator_alloc (struct ast_channel *chan, void *data) |
static int | silence_generator_generate (struct ast_channel *chan, void *data, int len, int samples) |
static void | silence_generator_release (struct ast_channel *chan, void *data) |
static void * | tonepair_alloc (struct ast_channel *chan, void *params) |
static int | tonepair_generator (struct ast_channel *chan, void *data, int len, int samples) |
static void | tonepair_release (struct ast_channel *chan, void *params) |
static void | update_bridge_vars (struct ast_channel *c0, struct ast_channel *c1) |
Variables | |
static void(*) | ast_moh_cleanup_ptr (struct ast_channel *) = NULL |
static int(*) | ast_moh_start_ptr (struct ast_channel *, const char *, const char *) = NULL |
static void(*) | ast_moh_stop_ptr (struct ast_channel *) = NULL |
ast_cause | causes [] |
map AST_CAUSE's to readable string representations | |
static struct ast_cli_entry | cli_channel [] |
unsigned long | global_fin |
unsigned long | global_fout |
static struct ast_channel_tech | null_tech |
static int | shutting_down |
Prevent new channel allocation if shutting down. | |
static struct ast_generator | silence_generator |
static struct ast_threadstorage | state2str_threadbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_state2str_threadbuf , .custom_init = NULL , } |
static struct ast_generator | tonepair |
static int | uniqueint |
Definition in file channel.c.
#define AST_DEFAULT_EMULATE_DTMF_DURATION 100 |
Default amount of time to use when emulating a digit as a begin and end 100ms
Definition at line 93 of file channel.c.
Referenced by __ast_read(), and ast_senddigit().
#define AST_MIN_DTMF_DURATION 80 |
Minimum allowed digit length - 80ms
Definition at line 96 of file channel.c.
Referenced by __ast_read().
#define AST_MIN_DTMF_GAP 45 |
Minimum amount of time between the end of the last digit and the beginning of a new one - 45ms
Definition at line 100 of file channel.c.
Referenced by __ast_read(), and should_skip_dtmf().
#define FORMAT "%-10.10s %-40.40s %-12.12s %-12.12s %-12.12s\n" |
#define STATE2STR_BUFSIZE 32 |
int __ast_answer | ( | struct ast_channel * | chan, | |
unsigned int | delay, | |||
int | cdr_answer | |||
) |
Answer a channel, with a selectable delay before returning.
chan | channel to answer | |
delay | maximum amount of time to wait for incoming media | |
cdr_answer | flag to control whether any associated CDR should be marked as 'answered' |
This function will wait up to 'delay' milliseconds for media to arrive on the channel before returning to the caller, so that the caller can properly assume the channel is 'ready' for media flow. If 'delay' is less than 500, the function will wait up to 500 milliseconds.
0 | on success | |
non-zero | on failure |
Definition at line 1829 of file channel.c.
References ast_channel::_state, ast_channel_lock, ast_channel_unlock, AST_CONTROL_HANGUP, ast_debug, AST_FRAME_CNG, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_frisolate(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK, AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_HEAD, ast_log(), ast_queue_frame_head(), ast_raw_answer(), ast_read(), AST_STATE_RING, AST_STATE_RINGING, ast_waitfor(), chanlist::chan, errno, frames, ast_frame::frametype, LOG_WARNING, MAX, ast_channel::name, and ast_frame::subclass.
Referenced by ast_answer(), dial_exec_full(), pbx_builtin_answer(), and pbx_builtin_incomplete().
01830 { 01831 int res = 0; 01832 enum ast_channel_state old_state; 01833 01834 old_state = chan->_state; 01835 if ((res = ast_raw_answer(chan, cdr_answer))) { 01836 return res; 01837 } 01838 01839 switch (old_state) { 01840 case AST_STATE_RINGING: 01841 case AST_STATE_RING: 01842 /* wait for media to start flowing, but don't wait any longer 01843 * than 'delay' or 500 milliseconds, whichever is longer 01844 */ 01845 do { 01846 AST_LIST_HEAD_NOLOCK(, ast_frame) frames; 01847 struct ast_frame *cur, *new; 01848 int ms = MAX(delay, 500); 01849 unsigned int done = 0; 01850 01851 AST_LIST_HEAD_INIT_NOLOCK(&frames); 01852 01853 for (;;) { 01854 ms = ast_waitfor(chan, ms); 01855 if (ms < 0) { 01856 ast_log(LOG_WARNING, "Error condition occurred when polling channel %s for a voice frame: %s\n", chan->name, strerror(errno)); 01857 res = -1; 01858 break; 01859 } 01860 if (ms == 0) { 01861 ast_debug(2, "Didn't receive a media frame from %s within %d ms of answering. Continuing anyway\n", chan->name, MAX(delay, 500)); 01862 break; 01863 } 01864 cur = ast_read(chan); 01865 if (!cur || ((cur->frametype == AST_FRAME_CONTROL) && 01866 (cur->subclass == AST_CONTROL_HANGUP))) { 01867 if (cur) { 01868 ast_frfree(cur); 01869 } 01870 res = -1; 01871 ast_debug(2, "Hangup of channel %s detected in answer routine\n", chan->name); 01872 break; 01873 } 01874 01875 if ((new = ast_frisolate(cur)) != cur) { 01876 ast_frfree(cur); 01877 } 01878 01879 AST_LIST_INSERT_HEAD(&frames, new, frame_list); 01880 01881 /* if a specific delay period was requested, continue 01882 * until that delay has passed. don't stop just because 01883 * incoming media has arrived. 01884 */ 01885 if (delay) { 01886 continue; 01887 } 01888 01889 switch (new->frametype) { 01890 /* all of these frametypes qualify as 'media' */ 01891 case AST_FRAME_VOICE: 01892 case AST_FRAME_VIDEO: 01893 case AST_FRAME_TEXT: 01894 case AST_FRAME_DTMF_BEGIN: 01895 case AST_FRAME_DTMF_END: 01896 case AST_FRAME_IMAGE: 01897 case AST_FRAME_HTML: 01898 case AST_FRAME_MODEM: 01899 done = 1; 01900 break; 01901 case AST_FRAME_CONTROL: 01902 case AST_FRAME_IAX: 01903 case AST_FRAME_NULL: 01904 case AST_FRAME_CNG: 01905 break; 01906 } 01907 01908 if (done) { 01909 break; 01910 } 01911 } 01912 01913 if (res == 0) { 01914 ast_channel_lock(chan); 01915 while ((cur = AST_LIST_REMOVE_HEAD(&frames, frame_list))) { 01916 ast_queue_frame_head(chan, cur); 01917 ast_frfree(cur); 01918 } 01919 ast_channel_unlock(chan); 01920 } 01921 } while (0); 01922 break; 01923 default: 01924 break; 01925 } 01926 01927 return res; 01928 }
struct ast_channel* __ast_channel_alloc | ( | int | needqueue, | |
int | state, | |||
const char * | cid_num, | |||
const char * | cid_name, | |||
const char * | acctcode, | |||
const char * | exten, | |||
const char * | context, | |||
const int | amaflag, | |||
const char * | file, | |||
int | line, | |||
const char * | function, | |||
const char * | name_fmt, | |||
... | ||||
) |
Create a channel structure.
NULL | failure | |
non-NULL | successfully allocated channel |
Definition at line 973 of file channel.c.
References __ast_channel_alloc_ap().
00978 { 00979 va_list ap1, ap2; 00980 struct ast_channel *result; 00981 00982 va_start(ap1, name_fmt); 00983 va_start(ap2, name_fmt); 00984 result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context, 00985 amaflag, file, line, function, name_fmt, ap1, ap2); 00986 va_end(ap1); 00987 va_end(ap2); 00988 00989 return result; 00990 }
static struct ast_channel* attribute_malloc __ast_channel_alloc_ap | ( | int | needqueue, | |
int | state, | |||
const char * | cid_num, | |||
const char * | cid_name, | |||
const char * | acctcode, | |||
const char * | exten, | |||
const char * | context, | |||
const int | amaflag, | |||
const char * | file, | |||
int | line, | |||
const char * | function, | |||
const char * | name_fmt, | |||
va_list | ap1, | |||
va_list | ap2 | |||
) | [static] |
Create a new channel structure.
Definition at line 771 of file channel.c.
References __ast_calloc(), accountcode, AST_ALERT_FD, ast_atomic_fetchadd_int(), ast_calloc, ast_cdr_alloc(), ast_cdr_init(), ast_cdr_start(), ast_channel_set_fd(), ast_config_AST_SYSTEM_NAME, ast_copy_string(), ast_default_accountcode, ast_default_amaflags, AST_FLAG_IN_CHANNEL_LIST, ast_free, ast_get_channel_tech(), AST_LIST_HEAD_INIT_NOLOCK, ast_log(), AST_MAX_FDS, ast_mutex_init(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_set_flag, ast_state2str(), ast_strdup, ast_strdupa, ast_string_field_build, ast_string_field_build_va, ast_string_field_free_memory, ast_string_field_init, ast_string_field_set, ast_strlen_zero(), ast_timer_close(), ast_timer_fd(), ast_timer_open(), AST_TIMING_FD, defaultlanguage, errno, EVENT_FLAG_CALL, chanlist::flags, language, LOG_WARNING, manager_event, name, null_tech, S_OR, sched_context_create(), sched_context_destroy(), and chanlist::tech.
Referenced by __ast_channel_alloc(), and ast_channel_alloc().
00775 { 00776 struct ast_channel *tmp; 00777 int x; 00778 int flags; 00779 struct varshead *headp; 00780 char *tech = ""; 00781 00782 /* If shutting down, don't allocate any new channels */ 00783 if (shutting_down) { 00784 ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n"); 00785 return NULL; 00786 } 00787 00788 #if defined(__AST_DEBUG_MALLOC) 00789 if (!(tmp = __ast_calloc(1, sizeof(*tmp), file, line, function))) { 00790 return NULL; 00791 } 00792 #else 00793 if (!(tmp = ast_calloc(1, sizeof(*tmp)))) { 00794 return NULL; 00795 } 00796 #endif 00797 00798 if (!(tmp->sched = sched_context_create())) { 00799 ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n"); 00800 ast_free(tmp); 00801 return NULL; 00802 } 00803 00804 if ((ast_string_field_init(tmp, 128))) { 00805 sched_context_destroy(tmp->sched); 00806 ast_free(tmp); 00807 return NULL; 00808 } 00809 00810 #ifdef HAVE_EPOLL 00811 tmp->epfd = epoll_create(25); 00812 #endif 00813 00814 for (x = 0; x < AST_MAX_FDS; x++) { 00815 tmp->fds[x] = -1; 00816 #ifdef HAVE_EPOLL 00817 tmp->epfd_data[x] = NULL; 00818 #endif 00819 } 00820 00821 if ((tmp->timer = ast_timer_open())) { 00822 needqueue = 0; 00823 tmp->timingfd = ast_timer_fd(tmp->timer); 00824 } else { 00825 tmp->timingfd = -1; 00826 } 00827 00828 if (needqueue) { 00829 if (pipe(tmp->alertpipe)) { 00830 ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe! Try increasing max file descriptors with ulimit -n\n"); 00831 alertpipe_failed: 00832 if (tmp->timer) { 00833 ast_timer_close(tmp->timer); 00834 } 00835 00836 sched_context_destroy(tmp->sched); 00837 ast_string_field_free_memory(tmp); 00838 ast_free(tmp); 00839 return NULL; 00840 } else { 00841 flags = fcntl(tmp->alertpipe[0], F_GETFL); 00842 if (fcntl(tmp->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) { 00843 ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno)); 00844 close(tmp->alertpipe[0]); 00845 close(tmp->alertpipe[1]); 00846 goto alertpipe_failed; 00847 } 00848 flags = fcntl(tmp->alertpipe[1], F_GETFL); 00849 if (fcntl(tmp->alertpipe[1], F_SETFL, flags | O_NONBLOCK) < 0) { 00850 ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno)); 00851 close(tmp->alertpipe[0]); 00852 close(tmp->alertpipe[1]); 00853 goto alertpipe_failed; 00854 } 00855 } 00856 } else /* Make sure we've got it done right if they don't */ 00857 tmp->alertpipe[0] = tmp->alertpipe[1] = -1; 00858 00859 /* Always watch the alertpipe */ 00860 ast_channel_set_fd(tmp, AST_ALERT_FD, tmp->alertpipe[0]); 00861 /* And timing pipe */ 00862 ast_channel_set_fd(tmp, AST_TIMING_FD, tmp->timingfd); 00863 ast_string_field_set(tmp, name, "**Unknown**"); 00864 00865 /* Initial state */ 00866 tmp->_state = state; 00867 00868 tmp->streamid = -1; 00869 00870 tmp->fin = global_fin; 00871 tmp->fout = global_fout; 00872 00873 if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) { 00874 ast_string_field_build(tmp, uniqueid, "%li.%d", (long) time(NULL), 00875 ast_atomic_fetchadd_int(&uniqueint, 1)); 00876 } else { 00877 ast_string_field_build(tmp, uniqueid, "%s-%li.%d", ast_config_AST_SYSTEM_NAME, 00878 (long) time(NULL), ast_atomic_fetchadd_int(&uniqueint, 1)); 00879 } 00880 00881 tmp->cid.cid_name = ast_strdup(cid_name); 00882 tmp->cid.cid_num = ast_strdup(cid_num); 00883 00884 if (!ast_strlen_zero(name_fmt)) { 00885 char *slash; 00886 /* Almost every channel is calling this function, and setting the name via the ast_string_field_build() call. 00887 * And they all use slightly different formats for their name string. 00888 * This means, to set the name here, we have to accept variable args, and call the string_field_build from here. 00889 * This means, that the stringfields must have a routine that takes the va_lists directly, and 00890 * uses them to build the string, instead of forming the va_lists internally from the vararg ... list. 00891 * This new function was written so this can be accomplished. 00892 */ 00893 ast_string_field_build_va(tmp, name, name_fmt, ap1, ap2); 00894 tech = ast_strdupa(tmp->name); 00895 if ((slash = strchr(tech, '/'))) { 00896 *slash = '\0'; 00897 } 00898 } 00899 00900 /* Reminder for the future: under what conditions do we NOT want to track cdrs on channels? */ 00901 00902 /* These 4 variables need to be set up for the cdr_init() to work right */ 00903 if (amaflag) 00904 tmp->amaflags = amaflag; 00905 else 00906 tmp->amaflags = ast_default_amaflags; 00907 00908 if (!ast_strlen_zero(acctcode)) 00909 ast_string_field_set(tmp, accountcode, acctcode); 00910 else 00911 ast_string_field_set(tmp, accountcode, ast_default_accountcode); 00912 00913 if (!ast_strlen_zero(context)) 00914 ast_copy_string(tmp->context, context, sizeof(tmp->context)); 00915 else 00916 strcpy(tmp->context, "default"); 00917 00918 if (!ast_strlen_zero(exten)) 00919 ast_copy_string(tmp->exten, exten, sizeof(tmp->exten)); 00920 else 00921 strcpy(tmp->exten, "s"); 00922 00923 tmp->priority = 1; 00924 00925 tmp->cdr = ast_cdr_alloc(); 00926 ast_cdr_init(tmp->cdr, tmp); 00927 ast_cdr_start(tmp->cdr); 00928 00929 headp = &tmp->varshead; 00930 AST_LIST_HEAD_INIT_NOLOCK(headp); 00931 00932 ast_mutex_init(&tmp->lock_dont_use); 00933 00934 AST_LIST_HEAD_INIT_NOLOCK(&tmp->datastores); 00935 00936 ast_string_field_set(tmp, language, defaultlanguage); 00937 00938 tmp->tech = &null_tech; 00939 00940 ast_set_flag(tmp, AST_FLAG_IN_CHANNEL_LIST); 00941 00942 AST_RWLIST_WRLOCK(&channels); 00943 AST_RWLIST_INSERT_HEAD(&channels, tmp, chan_list); 00944 AST_RWLIST_UNLOCK(&channels); 00945 00946 /*\!note 00947 * and now, since the channel structure is built, and has its name, let's 00948 * call the manager event generator with this Newchannel event. This is the 00949 * proper and correct place to make this call, but you sure do have to pass 00950 * a lot of data into this func to do it here! 00951 */ 00952 if (ast_get_channel_tech(tech)) { 00953 manager_event(EVENT_FLAG_CALL, "Newchannel", 00954 "Channel: %s\r\n" 00955 "ChannelState: %d\r\n" 00956 "ChannelStateDesc: %s\r\n" 00957 "CallerIDNum: %s\r\n" 00958 "CallerIDName: %s\r\n" 00959 "AccountCode: %s\r\n" 00960 "Uniqueid: %s\r\n", 00961 tmp->name, 00962 state, 00963 ast_state2str(state), 00964 S_OR(cid_num, ""), 00965 S_OR(cid_name, ""), 00966 tmp->accountcode, 00967 tmp->uniqueid); 00968 } 00969 00970 return tmp; 00971 }
static int __ast_queue_frame | ( | struct ast_channel * | chan, | |
struct ast_frame * | fin, | |||
int | head, | |||
struct ast_frame * | after | |||
) | [static] |
Definition at line 992 of file channel.c.
References ast_channel::alertpipe, ast_channel_lock, ast_channel_unlock, AST_CONTROL_HANGUP, AST_FLAG_BLOCKING, AST_FRAME_CONTROL, AST_FRAME_NULL, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frdup(), ast_frfree, AST_LIST_APPEND_LIST, AST_LIST_FIRST, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK, AST_LIST_INSERT_LIST_AFTER, AST_LIST_INSERT_TAIL, AST_LIST_LAST, AST_LIST_NEXT, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), ast_test_flag, ast_timer_enable_continuous(), ast_channel::blocker, chanlist::chan, errno, f, frames, ast_frame::frametype, LOG_WARNING, ast_channel::name, ast_channel::readq, ast_frame::subclass, ast_channel::timer, and ast_channel::timingfd.
Referenced by __ast_read(), ast_queue_frame(), and ast_queue_frame_head().
00993 { 00994 struct ast_frame *f; 00995 struct ast_frame *cur; 00996 int blah = 1; 00997 unsigned int new_frames = 0; 00998 unsigned int new_voice_frames = 0; 00999 unsigned int queued_frames = 0; 01000 unsigned int queued_voice_frames = 0; 01001 AST_LIST_HEAD_NOLOCK(, ast_frame) frames; 01002 01003 ast_channel_lock(chan); 01004 01005 /* See if the last frame on the queue is a hangup, if so don't queue anything */ 01006 if ((cur = AST_LIST_LAST(&chan->readq)) && 01007 (cur->frametype == AST_FRAME_CONTROL) && 01008 (cur->subclass == AST_CONTROL_HANGUP)) { 01009 ast_channel_unlock(chan); 01010 return 0; 01011 } 01012 01013 /* Build copies of all the frames and count them */ 01014 AST_LIST_HEAD_INIT_NOLOCK(&frames); 01015 for (cur = fin; cur; cur = AST_LIST_NEXT(cur, frame_list)) { 01016 if (!(f = ast_frdup(cur))) { 01017 ast_frfree(AST_LIST_FIRST(&frames)); 01018 ast_channel_unlock(chan); 01019 return -1; 01020 } 01021 01022 AST_LIST_INSERT_TAIL(&frames, f, frame_list); 01023 new_frames++; 01024 if (f->frametype == AST_FRAME_VOICE) { 01025 new_voice_frames++; 01026 } 01027 } 01028 01029 /* Count how many frames exist on the queue */ 01030 AST_LIST_TRAVERSE(&chan->readq, cur, frame_list) { 01031 queued_frames++; 01032 if (cur->frametype == AST_FRAME_VOICE) { 01033 queued_voice_frames++; 01034 } 01035 } 01036 01037 if ((queued_frames + new_frames > 128 || queued_voice_frames + new_voice_frames > 96)) { 01038 int count = 0; 01039 ast_log(LOG_WARNING, "Exceptionally long %squeue length queuing to %s\n", queued_frames + new_frames > 128 ? "" : "voice ", chan->name); 01040 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->readq, cur, frame_list) { 01041 /* Save the most recent frame */ 01042 if (!AST_LIST_NEXT(cur, frame_list)) { 01043 break; 01044 } else if (cur->frametype == AST_FRAME_VOICE || cur->frametype == AST_FRAME_VIDEO || cur->frametype == AST_FRAME_NULL) { 01045 if (++count > 64) { 01046 break; 01047 } 01048 AST_LIST_REMOVE_CURRENT(frame_list); 01049 ast_frfree(cur); 01050 } 01051 } 01052 AST_LIST_TRAVERSE_SAFE_END; 01053 } 01054 01055 if (after) { 01056 AST_LIST_INSERT_LIST_AFTER(&chan->readq, &frames, after, frame_list); 01057 } else { 01058 if (head) { 01059 AST_LIST_APPEND_LIST(&frames, &chan->readq, frame_list); 01060 AST_LIST_HEAD_INIT_NOLOCK(&chan->readq); 01061 } 01062 AST_LIST_APPEND_LIST(&chan->readq, &frames, frame_list); 01063 } 01064 01065 if (chan->alertpipe[1] > -1) { 01066 if (write(chan->alertpipe[1], &blah, new_frames * sizeof(blah)) != (new_frames * sizeof(blah))) { 01067 ast_log(LOG_WARNING, "Unable to write to alert pipe on %s (qlen = %d): %s!\n", 01068 chan->name, queued_frames, strerror(errno)); 01069 } 01070 } else if (chan->timingfd > -1) { 01071 ast_timer_enable_continuous(chan->timer); 01072 } else if (ast_test_flag(chan, AST_FLAG_BLOCKING)) { 01073 pthread_kill(chan->blocker, SIGURG); 01074 } 01075 01076 ast_channel_unlock(chan); 01077 01078 return 0; 01079 }
static struct ast_frame* __ast_read | ( | struct ast_channel * | chan, | |
int | dropaudio | |||
) | [static] |
Definition at line 2618 of file channel.c.
References __ast_queue_frame(), ast_channel::_softhangup, ast_channel::_state, ast_channel::alertpipe, AST_AUDIOHOOK_DIRECTION_READ, ast_audiohook_write_list(), ast_channel_trylock, ast_channel_unlock, ast_check_hangup(), ast_clear_flag, AST_CONTROL_ANSWER, AST_CONTROL_HANGUP, ast_deactivate_generator(), ast_debug, AST_DEFAULT_EMULATE_DTMF_DURATION, ast_do_masquerade(), AST_FLAG_DEFER_DTMF, AST_FLAG_EMULATE_DTMF, AST_FLAG_END_DTMF_ONLY, AST_FLAG_EXCEPTION, AST_FLAG_IN_DTMF, AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, ast_format_rate(), AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_frame_dump(), AST_FRAME_NULL, AST_FRAME_VOICE, ast_frfree, AST_GENERATOR_FD, ast_getformatname(), ast_getformatname_multiple(), AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_LAST, AST_LIST_NEXT, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), AST_MIN_DTMF_DURATION, AST_MIN_DTMF_GAP, AST_MONITOR_RUNNING, ast_null_frame, ast_queue_frame(), ast_queue_frame_head(), ast_read_generator_actions(), ast_seekstream(), ast_set_flag, ast_setstate(), AST_SOFTHANGUP_DEV, AST_STATE_UP, ast_test_flag, ast_timer_ack(), ast_timer_disable_continuous(), ast_timer_get_event(), ast_timer_set_rate(), AST_TIMING_EVENT_CONTINUOUS, AST_TIMING_EVENT_EXPIRED, AST_TIMING_FD, ast_translate(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), ast_writestream(), ast_channel::audiohooks, ast_channel::blocker, calc_monitor_jump(), chanlist::chan, DEBUGCHAN_FLAG, ast_generator::digit, ast_channel::dtmf_tv, ast_channel::dtmff, ast_channel::emulate_dtmf_digit, ast_channel::emulate_dtmf_duration, errno, ast_channel_tech::exception, f, ast_channel::fdno, ast_channel::fds, ast_channel::fin, chanlist::flags, ast_filestream::fmt, ast_format::format, FRAMECOUNT_INC, ast_generator::generate, ast_channel::generator, ast_channel::generatordata, ast_channel::hangupcause, ast_channel::insmpl, LOG_DTMF, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_channel::masq, ast_channel::monitor, ast_channel::music_state, ast_channel::name, ast_channel::nativeformats, ast_channel::outsmpl, queue_dtmf_readq(), ast_channel_tech::read, ast_channel_monitor::read_stream, ast_channel::readq, ast_channel::readtrans, SEEK_FORCECUR, send_dtmf_event(), should_skip_dtmf(), ast_channel_monitor::state, ast_channel::tech, ast_channel::timer, ast_channel::timingdata, ast_channel::timingfd, and ast_channel::timingfunc.
Referenced by ast_read(), and ast_read_noaudio().
02619 { 02620 struct ast_frame *f = NULL; /* the return value */ 02621 int blah; 02622 int prestate; 02623 int count = 0, cause = 0; 02624 02625 /* this function is very long so make sure there is only one return 02626 * point at the end (there are only two exceptions to this). 02627 */ 02628 while(ast_channel_trylock(chan)) { 02629 if(count++ > 10) 02630 /*cannot goto done since the channel is not locked*/ 02631 return &ast_null_frame; 02632 usleep(1); 02633 } 02634 02635 if (chan->masq) { 02636 if (ast_do_masquerade(chan)) 02637 ast_log(LOG_WARNING, "Failed to perform masquerade\n"); 02638 else 02639 f = &ast_null_frame; 02640 goto done; 02641 } 02642 02643 /* Stop if we're a zombie or need a soft hangup */ 02644 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 02645 if (chan->generator) 02646 ast_deactivate_generator(chan); 02647 goto done; 02648 } 02649 02650 #ifdef AST_DEVMODE 02651 /* 02652 * The ast_waitfor() code records which of the channel's file descriptors reported that 02653 * data is available. In theory, ast_read() should only be called after ast_waitfor() 02654 * reports that a channel has data available for reading. However, there still may be 02655 * some edge cases throughout the code where ast_read() is called improperly. This can 02656 * potentially cause problems, so if this is a developer build, make a lot of noise if 02657 * this happens so that it can be addressed. 02658 */ 02659 if (chan->fdno == -1) { 02660 ast_log(LOG_ERROR, "ast_read() called with no recorded file descriptor.\n"); 02661 } 02662 #endif 02663 02664 prestate = chan->_state; 02665 02666 /* Read and ignore anything on the alertpipe, but read only 02667 one sizeof(blah) per frame that we send from it */ 02668 if (chan->alertpipe[0] > -1) { 02669 int flags = fcntl(chan->alertpipe[0], F_GETFL); 02670 /* For some odd reason, the alertpipe occasionally loses nonblocking status, 02671 * which immediately causes a deadlock scenario. Detect and prevent this. */ 02672 if ((flags & O_NONBLOCK) == 0) { 02673 ast_log(LOG_ERROR, "Alertpipe on channel %s lost O_NONBLOCK?!!\n", chan->name); 02674 if (fcntl(chan->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) { 02675 ast_log(LOG_WARNING, "Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno)); 02676 f = &ast_null_frame; 02677 goto done; 02678 } 02679 } 02680 if (read(chan->alertpipe[0], &blah, sizeof(blah)) < 0) { 02681 if (errno != EINTR && errno != EAGAIN) 02682 ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno)); 02683 } 02684 } 02685 02686 if (chan->timingfd > -1 && chan->fdno == AST_TIMING_FD) { 02687 enum ast_timer_event res; 02688 02689 ast_clear_flag(chan, AST_FLAG_EXCEPTION); 02690 02691 res = ast_timer_get_event(chan->timer); 02692 02693 switch (res) { 02694 case AST_TIMING_EVENT_EXPIRED: 02695 ast_timer_ack(chan->timer, 1); 02696 02697 if (chan->timingfunc) { 02698 /* save a copy of func/data before unlocking the channel */ 02699 int (*func)(const void *) = chan->timingfunc; 02700 void *data = chan->timingdata; 02701 chan->fdno = -1; 02702 ast_channel_unlock(chan); 02703 func(data); 02704 } else { 02705 ast_timer_set_rate(chan->timer, 0); 02706 chan->fdno = -1; 02707 ast_channel_unlock(chan); 02708 } 02709 02710 /* cannot 'goto done' because the channel is already unlocked */ 02711 return &ast_null_frame; 02712 02713 case AST_TIMING_EVENT_CONTINUOUS: 02714 if (AST_LIST_EMPTY(&chan->readq) || 02715 !AST_LIST_NEXT(AST_LIST_FIRST(&chan->readq), frame_list)) { 02716 ast_timer_disable_continuous(chan->timer); 02717 } 02718 break; 02719 } 02720 02721 } else if (chan->fds[AST_GENERATOR_FD] > -1 && chan->fdno == AST_GENERATOR_FD) { 02722 /* if the AST_GENERATOR_FD is set, call the generator with args 02723 * set to -1 so it can do whatever it needs to. 02724 */ 02725 void *tmp = chan->generatordata; 02726 chan->generatordata = NULL; /* reset to let ast_write get through */ 02727 chan->generator->generate(chan, tmp, -1, -1); 02728 chan->generatordata = tmp; 02729 f = &ast_null_frame; 02730 chan->fdno = -1; 02731 goto done; 02732 } 02733 02734 /* Check for pending read queue */ 02735 if (!AST_LIST_EMPTY(&chan->readq)) { 02736 int skip_dtmf = should_skip_dtmf(chan); 02737 02738 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->readq, f, frame_list) { 02739 /* We have to be picky about which frame we pull off of the readq because 02740 * there are cases where we want to leave DTMF frames on the queue until 02741 * some later time. */ 02742 02743 if ( (f->frametype == AST_FRAME_DTMF_BEGIN || f->frametype == AST_FRAME_DTMF_END) && skip_dtmf) { 02744 continue; 02745 } 02746 02747 AST_LIST_REMOVE_CURRENT(frame_list); 02748 break; 02749 } 02750 AST_LIST_TRAVERSE_SAFE_END; 02751 02752 if (!f) { 02753 /* There were no acceptable frames on the readq. */ 02754 f = &ast_null_frame; 02755 if (chan->alertpipe[0] > -1) { 02756 int poke = 0; 02757 /* Restore the state of the alertpipe since we aren't ready for any 02758 * of the frames in the readq. */ 02759 if (write(chan->alertpipe[1], &poke, sizeof(poke)) != sizeof(poke)) { 02760 ast_log(LOG_ERROR, "Failed to write to alertpipe: %s\n", strerror(errno)); 02761 } 02762 } 02763 } 02764 02765 /* Interpret hangup and return NULL */ 02766 /* XXX why not the same for frames from the channel ? */ 02767 if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) { 02768 cause = f->data.uint32; 02769 ast_frfree(f); 02770 f = NULL; 02771 } 02772 } else { 02773 chan->blocker = pthread_self(); 02774 if (ast_test_flag(chan, AST_FLAG_EXCEPTION)) { 02775 if (chan->tech->exception) 02776 f = chan->tech->exception(chan); 02777 else { 02778 ast_log(LOG_WARNING, "Exception flag set on '%s', but no exception handler\n", chan->name); 02779 f = &ast_null_frame; 02780 } 02781 /* Clear the exception flag */ 02782 ast_clear_flag(chan, AST_FLAG_EXCEPTION); 02783 } else if (chan->tech->read) 02784 f = chan->tech->read(chan); 02785 else 02786 ast_log(LOG_WARNING, "No read routine on channel %s\n", chan->name); 02787 } 02788 02789 /* 02790 * Reset the recorded file descriptor that triggered this read so that we can 02791 * easily detect when ast_read() is called without properly using ast_waitfor(). 02792 */ 02793 chan->fdno = -1; 02794 02795 if (f) { 02796 struct ast_frame *readq_tail = AST_LIST_LAST(&chan->readq); 02797 02798 /* if the channel driver returned more than one frame, stuff the excess 02799 into the readq for the next ast_read call 02800 */ 02801 if (AST_LIST_NEXT(f, frame_list)) { 02802 ast_queue_frame(chan, AST_LIST_NEXT(f, frame_list)); 02803 ast_frfree(AST_LIST_NEXT(f, frame_list)); 02804 AST_LIST_NEXT(f, frame_list) = NULL; 02805 } 02806 02807 switch (f->frametype) { 02808 case AST_FRAME_CONTROL: 02809 if (f->subclass == AST_CONTROL_ANSWER) { 02810 if (!ast_test_flag(chan, AST_FLAG_OUTGOING)) { 02811 ast_debug(1, "Ignoring answer on an inbound call!\n"); 02812 ast_frfree(f); 02813 f = &ast_null_frame; 02814 } else if (prestate == AST_STATE_UP) { 02815 ast_debug(1, "Dropping duplicate answer!\n"); 02816 ast_frfree(f); 02817 f = &ast_null_frame; 02818 } else { 02819 /* Answer the CDR */ 02820 ast_setstate(chan, AST_STATE_UP); 02821 /* removed a call to ast_cdr_answer(chan->cdr) from here. */ 02822 } 02823 } 02824 break; 02825 case AST_FRAME_DTMF_END: 02826 send_dtmf_event(chan, "Received", f->subclass, "No", "Yes"); 02827 ast_log(LOG_DTMF, "DTMF end '%c' received on %s, duration %ld ms\n", f->subclass, chan->name, f->len); 02828 /* Queue it up if DTMF is deferred, or if DTMF emulation is forced. */ 02829 if (ast_test_flag(chan, AST_FLAG_DEFER_DTMF) || ast_test_flag(chan, AST_FLAG_EMULATE_DTMF)) { 02830 queue_dtmf_readq(chan, f); 02831 ast_frfree(f); 02832 f = &ast_null_frame; 02833 } else if (!ast_test_flag(chan, AST_FLAG_IN_DTMF | AST_FLAG_END_DTMF_ONLY)) { 02834 if (!ast_tvzero(chan->dtmf_tv) && 02835 ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) { 02836 /* If it hasn't been long enough, defer this digit */ 02837 queue_dtmf_readq(chan, f); 02838 ast_frfree(f); 02839 f = &ast_null_frame; 02840 } else { 02841 /* There was no begin, turn this into a begin and send the end later */ 02842 f->frametype = AST_FRAME_DTMF_BEGIN; 02843 ast_set_flag(chan, AST_FLAG_EMULATE_DTMF); 02844 chan->emulate_dtmf_digit = f->subclass; 02845 chan->dtmf_tv = ast_tvnow(); 02846 if (f->len) { 02847 if (f->len > AST_MIN_DTMF_DURATION) 02848 chan->emulate_dtmf_duration = f->len; 02849 else 02850 chan->emulate_dtmf_duration = AST_MIN_DTMF_DURATION; 02851 } else 02852 chan->emulate_dtmf_duration = AST_DEFAULT_EMULATE_DTMF_DURATION; 02853 ast_log(LOG_DTMF, "DTMF begin emulation of '%c' with duration %u queued on %s\n", f->subclass, chan->emulate_dtmf_duration, chan->name); 02854 } 02855 if (chan->audiohooks) { 02856 struct ast_frame *old_frame = f; 02857 /*! 02858 * \todo XXX It is possible to write a digit to the audiohook twice 02859 * if the digit was originally read while the channel was in autoservice. */ 02860 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 02861 if (old_frame != f) 02862 ast_frfree(old_frame); 02863 } 02864 } else { 02865 struct timeval now = ast_tvnow(); 02866 if (ast_test_flag(chan, AST_FLAG_IN_DTMF)) { 02867 ast_log(LOG_DTMF, "DTMF end accepted with begin '%c' on %s\n", f->subclass, chan->name); 02868 ast_clear_flag(chan, AST_FLAG_IN_DTMF); 02869 if (!f->len) 02870 f->len = ast_tvdiff_ms(now, chan->dtmf_tv); 02871 } else if (!f->len) { 02872 ast_log(LOG_DTMF, "DTMF end accepted without begin '%c' on %s\n", f->subclass, chan->name); 02873 f->len = AST_MIN_DTMF_DURATION; 02874 } 02875 if (f->len < AST_MIN_DTMF_DURATION && !ast_test_flag(chan, AST_FLAG_END_DTMF_ONLY)) { 02876 ast_log(LOG_DTMF, "DTMF end '%c' has duration %ld but want minimum %d, emulating on %s\n", f->subclass, f->len, AST_MIN_DTMF_DURATION, chan->name); 02877 ast_set_flag(chan, AST_FLAG_EMULATE_DTMF); 02878 chan->emulate_dtmf_digit = f->subclass; 02879 chan->emulate_dtmf_duration = AST_MIN_DTMF_DURATION - f->len; 02880 ast_frfree(f); 02881 f = &ast_null_frame; 02882 } else { 02883 ast_log(LOG_DTMF, "DTMF end passthrough '%c' on %s\n", f->subclass, chan->name); 02884 if (f->len < AST_MIN_DTMF_DURATION) { 02885 f->len = AST_MIN_DTMF_DURATION; 02886 } 02887 chan->dtmf_tv = now; 02888 } 02889 if (chan->audiohooks) { 02890 struct ast_frame *old_frame = f; 02891 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 02892 if (old_frame != f) 02893 ast_frfree(old_frame); 02894 } 02895 } 02896 break; 02897 case AST_FRAME_DTMF_BEGIN: 02898 send_dtmf_event(chan, "Received", f->subclass, "Yes", "No"); 02899 ast_log(LOG_DTMF, "DTMF begin '%c' received on %s\n", f->subclass, chan->name); 02900 if ( ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_END_DTMF_ONLY | AST_FLAG_EMULATE_DTMF) || 02901 (!ast_tvzero(chan->dtmf_tv) && 02902 ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) ) { 02903 ast_log(LOG_DTMF, "DTMF begin ignored '%c' on %s\n", f->subclass, chan->name); 02904 ast_frfree(f); 02905 f = &ast_null_frame; 02906 } else { 02907 ast_set_flag(chan, AST_FLAG_IN_DTMF); 02908 chan->dtmf_tv = ast_tvnow(); 02909 ast_log(LOG_DTMF, "DTMF begin passthrough '%c' on %s\n", f->subclass, chan->name); 02910 } 02911 break; 02912 case AST_FRAME_NULL: 02913 /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration 02914 * is reached , because we want to make sure we pass at least one 02915 * voice frame through before starting the next digit, to ensure a gap 02916 * between DTMF digits. */ 02917 if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF)) { 02918 struct timeval now = ast_tvnow(); 02919 if (!chan->emulate_dtmf_duration) { 02920 ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF); 02921 chan->emulate_dtmf_digit = 0; 02922 } else if (ast_tvdiff_ms(now, chan->dtmf_tv) >= chan->emulate_dtmf_duration) { 02923 chan->emulate_dtmf_duration = 0; 02924 ast_frfree(f); 02925 f = &chan->dtmff; 02926 f->frametype = AST_FRAME_DTMF_END; 02927 f->subclass = chan->emulate_dtmf_digit; 02928 f->len = ast_tvdiff_ms(now, chan->dtmf_tv); 02929 chan->dtmf_tv = now; 02930 ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF); 02931 chan->emulate_dtmf_digit = 0; 02932 ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass, chan->name); 02933 if (chan->audiohooks) { 02934 struct ast_frame *old_frame = f; 02935 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 02936 if (old_frame != f) { 02937 ast_frfree(old_frame); 02938 } 02939 } 02940 } 02941 } 02942 break; 02943 case AST_FRAME_VOICE: 02944 /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration 02945 * is reached , because we want to make sure we pass at least one 02946 * voice frame through before starting the next digit, to ensure a gap 02947 * between DTMF digits. */ 02948 if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF) && !chan->emulate_dtmf_duration) { 02949 ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF); 02950 chan->emulate_dtmf_digit = 0; 02951 } 02952 02953 if (dropaudio || ast_test_flag(chan, AST_FLAG_IN_DTMF)) { 02954 if (dropaudio) 02955 ast_read_generator_actions(chan, f); 02956 ast_frfree(f); 02957 f = &ast_null_frame; 02958 } 02959 02960 if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF) && !ast_test_flag(chan, AST_FLAG_IN_DTMF)) { 02961 struct timeval now = ast_tvnow(); 02962 if (ast_tvdiff_ms(now, chan->dtmf_tv) >= chan->emulate_dtmf_duration) { 02963 chan->emulate_dtmf_duration = 0; 02964 ast_frfree(f); 02965 f = &chan->dtmff; 02966 f->frametype = AST_FRAME_DTMF_END; 02967 f->subclass = chan->emulate_dtmf_digit; 02968 f->len = ast_tvdiff_ms(now, chan->dtmf_tv); 02969 chan->dtmf_tv = now; 02970 if (chan->audiohooks) { 02971 struct ast_frame *old_frame = f; 02972 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 02973 if (old_frame != f) 02974 ast_frfree(old_frame); 02975 } 02976 ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass, chan->name); 02977 } else { 02978 /* Drop voice frames while we're still in the middle of the digit */ 02979 ast_frfree(f); 02980 f = &ast_null_frame; 02981 } 02982 } else if ((f->frametype == AST_FRAME_VOICE) && !(f->subclass & chan->nativeformats)) { 02983 /* This frame is not one of the current native formats -- drop it on the floor */ 02984 char to[200]; 02985 ast_log(LOG_NOTICE, "Dropping incompatible voice frame on %s of format %s since our native format has changed to %s\n", 02986 chan->name, ast_getformatname(f->subclass), ast_getformatname_multiple(to, sizeof(to), chan->nativeformats)); 02987 ast_frfree(f); 02988 f = &ast_null_frame; 02989 } else if ((f->frametype == AST_FRAME_VOICE)) { 02990 /* Send frame to audiohooks if present */ 02991 if (chan->audiohooks) { 02992 struct ast_frame *old_frame = f; 02993 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 02994 if (old_frame != f) 02995 ast_frfree(old_frame); 02996 } 02997 if (chan->monitor && chan->monitor->read_stream ) { 02998 /* XXX what does this do ? */ 02999 #ifndef MONITOR_CONSTANT_DELAY 03000 int jump = chan->outsmpl - chan->insmpl - 4 * f->samples; 03001 if (jump >= 0) { 03002 jump = calc_monitor_jump((chan->outsmpl - chan->insmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format)); 03003 if (ast_seekstream(chan->monitor->read_stream, jump, SEEK_FORCECUR) == -1) 03004 ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n"); 03005 chan->insmpl += (chan->outsmpl - chan->insmpl) + f->samples; 03006 } else 03007 chan->insmpl+= f->samples; 03008 #else 03009 int jump = calc_monitor_jump((chan->outsmpl - chan->insmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format)); 03010 if (jump - MONITOR_DELAY >= 0) { 03011 if (ast_seekstream(chan->monitor->read_stream, jump - f->samples, SEEK_FORCECUR) == -1) 03012 ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n"); 03013 chan->insmpl += chan->outsmpl - chan->insmpl; 03014 } else 03015 chan->insmpl += f->samples; 03016 #endif 03017 if (chan->monitor->state == AST_MONITOR_RUNNING) { 03018 if (ast_writestream(chan->monitor->read_stream, f) < 0) 03019 ast_log(LOG_WARNING, "Failed to write data to channel monitor read stream\n"); 03020 } 03021 } 03022 03023 if (chan->readtrans && (f = ast_translate(chan->readtrans, f, 1)) == NULL) { 03024 f = &ast_null_frame; 03025 } 03026 03027 /* it is possible for the translation process on chan->readtrans to have 03028 produced multiple frames from the single input frame we passed it; if 03029 this happens, queue the additional frames *before* the frames we may 03030 have queued earlier. if the readq was empty, put them at the head of 03031 the queue, and if it was not, put them just after the frame that was 03032 at the end of the queue. 03033 */ 03034 if (AST_LIST_NEXT(f, frame_list)) { 03035 if (!readq_tail) { 03036 ast_queue_frame_head(chan, AST_LIST_NEXT(f, frame_list)); 03037 } else { 03038 __ast_queue_frame(chan, AST_LIST_NEXT(f, frame_list), 0, readq_tail); 03039 } 03040 ast_frfree(AST_LIST_NEXT(f, frame_list)); 03041 AST_LIST_NEXT(f, frame_list) = NULL; 03042 } 03043 03044 /* Run generator sitting on the line if timing device not available 03045 * and synchronous generation of outgoing frames is necessary */ 03046 ast_read_generator_actions(chan, f); 03047 } 03048 default: 03049 /* Just pass it on! */ 03050 break; 03051 } 03052 } else { 03053 /* Make sure we always return NULL in the future */ 03054 chan->_softhangup |= AST_SOFTHANGUP_DEV; 03055 if (cause) 03056 chan->hangupcause = cause; 03057 if (chan->generator) 03058 ast_deactivate_generator(chan); 03059 /* We no longer End the CDR here */ 03060 } 03061 03062 /* High bit prints debugging */ 03063 if (chan->fin & DEBUGCHAN_FLAG) 03064 ast_frame_dump(chan->name, f, "<<"); 03065 chan->fin = FRAMECOUNT_INC(chan->fin); 03066 03067 done: 03068 if (chan->music_state && chan->generator && chan->generator->digit && f && f->frametype == AST_FRAME_DTMF_END) 03069 chan->generator->digit(chan, f->subclass); 03070 03071 ast_channel_unlock(chan); 03072 return f; 03073 }
struct ast_channel* __ast_request_and_dial | ( | const char * | type, | |
int | format, | |||
void * | data, | |||
int | timeout, | |||
int * | reason, | |||
const char * | cid_num, | |||
const char * | cid_name, | |||
struct outgoing_helper * | oh | |||
) |
Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it.
type | type of channel to request | |
format | requested channel format | |
data | data to pass to the channel requester | |
timeout | maximum amount of time to wait for an answer | |
reason | why unsuccessful (if unsuccessful) | |
cid_num | Caller-ID Number | |
cid_name | Caller-ID Name (ascii) | |
oh | Outgoing helper |
Definition at line 3832 of file channel.c.
References ast_channel::_state, outgoing_helper::account, ast_call(), ast_call_forward(), AST_CAUSE_NO_ANSWER, ast_cdr_alloc(), ast_cdr_answer(), ast_cdr_busy(), ast_cdr_disposition(), ast_cdr_end(), ast_cdr_failed(), AST_CDR_FLAG_ORIGINATED, ast_cdr_init(), ast_cdr_setaccount(), ast_cdr_setapp(), ast_cdr_start(), ast_cdr_update(), ast_channel_datastore_inherit(), ast_channel_inherit_variables(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_copy_string(), AST_FRAME_CONTROL, ast_frfree, ast_hangup(), ast_log(), ast_read(), ast_request(), ast_set_callerid(), ast_set_flag, ast_set_variables(), AST_STATE_UP, ast_strlen_zero(), ast_waitfor(), ast_channel::call_forward, ast_channel::cdr, chanlist::chan, outgoing_helper::cid_name, outgoing_helper::cid_num, outgoing_helper::context, ast_channel::context, outgoing_helper::exten, ast_channel::exten, f, handle_cause(), ast_channel::hangupcause, LOG_NOTICE, outgoing_helper::parent_channel, outgoing_helper::priority, ast_channel::priority, and outgoing_helper::vars.
Referenced by ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_request_and_dial(), and parkandannounce_exec().
03833 { 03834 int dummy_outstate; 03835 int cause = 0; 03836 struct ast_channel *chan; 03837 int res = 0; 03838 int last_subclass = 0; 03839 03840 if (outstate) 03841 *outstate = 0; 03842 else 03843 outstate = &dummy_outstate; /* make outstate always a valid pointer */ 03844 03845 chan = ast_request(type, format, data, &cause); 03846 if (!chan) { 03847 ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data); 03848 handle_cause(cause, outstate); 03849 return NULL; 03850 } 03851 03852 if (oh) { 03853 if (oh->vars) 03854 ast_set_variables(chan, oh->vars); 03855 /* XXX why is this necessary, for the parent_channel perhaps ? */ 03856 if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) 03857 ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num); 03858 if (oh->parent_channel) { 03859 ast_channel_inherit_variables(oh->parent_channel, chan); 03860 ast_channel_datastore_inherit(oh->parent_channel, chan); 03861 } 03862 if (oh->account) 03863 ast_cdr_setaccount(chan, oh->account); 03864 } 03865 ast_set_callerid(chan, cid_num, cid_name, cid_num); 03866 ast_set_flag(chan->cdr, AST_CDR_FLAG_ORIGINATED); 03867 03868 if (ast_call(chan, data, 0)) { /* ast_call failed... */ 03869 ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data); 03870 } else { 03871 res = 1; /* mark success in case chan->_state is already AST_STATE_UP */ 03872 while (timeout && chan->_state != AST_STATE_UP) { 03873 struct ast_frame *f; 03874 res = ast_waitfor(chan, timeout); 03875 if (res == 0) { /* timeout, treat it like ringing */ 03876 *outstate = AST_CONTROL_RINGING; 03877 break; 03878 } 03879 if (res < 0) /* error or done */ 03880 break; 03881 if (timeout > -1) 03882 timeout = res; 03883 if (!ast_strlen_zero(chan->call_forward)) { 03884 if (!(chan = ast_call_forward(NULL, chan, &timeout, format, oh, outstate))) { 03885 return NULL; 03886 } 03887 continue; 03888 } 03889 03890 f = ast_read(chan); 03891 if (!f) { 03892 *outstate = AST_CONTROL_HANGUP; 03893 res = 0; 03894 break; 03895 } 03896 if (f->frametype == AST_FRAME_CONTROL) { 03897 switch (f->subclass) { 03898 case AST_CONTROL_RINGING: /* record but keep going */ 03899 *outstate = f->subclass; 03900 break; 03901 03902 case AST_CONTROL_BUSY: 03903 ast_cdr_busy(chan->cdr); 03904 *outstate = f->subclass; 03905 timeout = 0; 03906 break; 03907 03908 case AST_CONTROL_CONGESTION: 03909 ast_cdr_failed(chan->cdr); 03910 *outstate = f->subclass; 03911 timeout = 0; 03912 break; 03913 03914 case AST_CONTROL_ANSWER: 03915 ast_cdr_answer(chan->cdr); 03916 *outstate = f->subclass; 03917 timeout = 0; /* trick to force exit from the while() */ 03918 break; 03919 03920 /* Ignore these */ 03921 case AST_CONTROL_PROGRESS: 03922 case AST_CONTROL_PROCEEDING: 03923 case AST_CONTROL_HOLD: 03924 case AST_CONTROL_UNHOLD: 03925 case AST_CONTROL_VIDUPDATE: 03926 case AST_CONTROL_SRCUPDATE: 03927 case AST_CONTROL_SRCCHANGE: 03928 case -1: /* Ignore -- just stopping indications */ 03929 break; 03930 03931 default: 03932 ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass); 03933 } 03934 last_subclass = f->subclass; 03935 } 03936 ast_frfree(f); 03937 } 03938 } 03939 03940 /* Final fixups */ 03941 if (oh) { 03942 if (!ast_strlen_zero(oh->context)) 03943 ast_copy_string(chan->context, oh->context, sizeof(chan->context)); 03944 if (!ast_strlen_zero(oh->exten)) 03945 ast_copy_string(chan->exten, oh->exten, sizeof(chan->exten)); 03946 if (oh->priority) 03947 chan->priority = oh->priority; 03948 } 03949 if (chan->_state == AST_STATE_UP) 03950 *outstate = AST_CONTROL_ANSWER; 03951 03952 if (res <= 0) { 03953 if ( AST_CONTROL_RINGING == last_subclass ) 03954 chan->hangupcause = AST_CAUSE_NO_ANSWER; 03955 if (!chan->cdr && (chan->cdr = ast_cdr_alloc())) 03956 ast_cdr_init(chan->cdr, chan); 03957 if (chan->cdr) { 03958 char tmp[256]; 03959 snprintf(tmp, sizeof(tmp), "%s/%s", type, (char *)data); 03960 ast_cdr_setapp(chan->cdr,"Dial",tmp); 03961 ast_cdr_update(chan); 03962 ast_cdr_start(chan->cdr); 03963 ast_cdr_end(chan->cdr); 03964 /* If the cause wasn't handled properly */ 03965 if (ast_cdr_disposition(chan->cdr,chan->hangupcause)) 03966 ast_cdr_failed(chan->cdr); 03967 } 03968 ast_hangup(chan); 03969 chan = NULL; 03970 } 03971 return chan; 03972 }
static void __init_state2str_threadbuf | ( | void | ) | [static] |
int ast_activate_generator | ( | struct ast_channel * | chan, | |
struct ast_generator * | gen, | |||
void * | params | |||
) |
Activate a given generator
Definition at line 1980 of file channel.c.
References ast_generator::alloc, ast_channel_lock, ast_channel_unlock, ast_prod(), ast_settimeout(), chanlist::chan, gen, ast_channel::generator, generator_force(), ast_channel::generatordata, and ast_generator::release.
Referenced by app_exec(), ast_channel_start_silence_generator(), ast_linear_stream(), ast_playtones_start(), ast_tonepair_start(), channel_spy(), eivr_comm(), old_milliwatt_exec(), and transmit_audio().
01981 { 01982 int res = 0; 01983 01984 ast_channel_lock(chan); 01985 if (chan->generatordata) { 01986 if (chan->generator && chan->generator->release) 01987 chan->generator->release(chan, chan->generatordata); 01988 chan->generatordata = NULL; 01989 } 01990 if (gen->alloc && !(chan->generatordata = gen->alloc(chan, params))) { 01991 res = -1; 01992 } 01993 if (!res) { 01994 ast_settimeout(chan, 50, generator_force, chan); 01995 chan->generator = gen; 01996 } 01997 ast_channel_unlock(chan); 01998 01999 ast_prod(chan); 02000 02001 return res; 02002 }
int ast_active_channels | ( | void | ) |
returns number of active/allocated channels
Returns number of active/allocated channels
Definition at line 498 of file channel.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, and AST_RWLIST_UNLOCK.
Referenced by action_corestatus(), dahdi_restart(), handle_show_settings(), and quit_handler().
00499 { 00500 struct ast_channel *c; 00501 int cnt = 0; 00502 AST_RWLIST_RDLOCK(&channels); 00503 AST_RWLIST_TRAVERSE(&channels, c, chan_list) 00504 cnt++; 00505 AST_RWLIST_UNLOCK(&channels); 00506 return cnt; 00507 }
int ast_answer | ( | struct ast_channel * | chan | ) |
Answer a channel.
chan | channel to answer |
This function will wait up to 500 milliseconds for media to arrive on the channel before returning to the caller, so that the caller can properly assume the channel is 'ready' for media flow.
0 | on success | |
non-zero | on failure |
Definition at line 1930 of file channel.c.
References __ast_answer(), and chanlist::chan.
Referenced by action_bridge(), agi_exec_full(), alarmreceiver_exec(), answer_trunk_chan(), app_exec(), ast_control_streamfile(), ast_pickup_call(), auth_exec(), background_detect_exec(), bridge_exec(), builtin_parkcall(), common_exec(), conf_exec(), count_exec(), dahdiras_exec(), dictate_exec(), directory_exec(), disa_exec(), eivr_comm(), handle_answer(), ices_exec(), login_exec(), minivm_accmess_exec(), minivm_greet_exec(), minivm_record_exec(), old_milliwatt_exec(), park_call_exec(), park_exec_full(), pbx_builtin_background(), pickup_do(), playback_exec(), privacy_exec(), read_exec(), readexten_exec(), rpt_exec(), sayunixtime_exec(), send_waveform_to_channel(), setup_privacy_args(), skel_exec(), sla_station_exec(), speech_background(), testclient_exec(), testserver_exec(), transmit(), vm_exec(), vm_execmain(), waitfor_exec(), and zapateller_exec().
01931 { 01932 return __ast_answer(chan, 0, 1); 01933 }
void ast_begin_shutdown | ( | int | hangup | ) |
Initiate system shutdown.
Initiate system shutdown -- prevents new channels from being allocated. If "hangup" is non-zero, all existing channels will receive soft hangups
Definition at line 484 of file channel.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_softhangup(), and AST_SOFTHANGUP_SHUTDOWN.
Referenced by quit_handler().
00485 { 00486 struct ast_channel *c; 00487 shutting_down = 1; 00488 if (hangup) { 00489 AST_RWLIST_RDLOCK(&channels); 00490 AST_RWLIST_TRAVERSE(&channels, c, chan_list) { 00491 ast_softhangup(c, AST_SOFTHANGUP_SHUTDOWN); 00492 } 00493 AST_RWLIST_UNLOCK(&channels); 00494 } 00495 }
int ast_best_codec | ( | int | fmts | ) |
Pick the best audio codec.
Pick the best codec
Okay, ulaw is used by all telephony equipment, so start with it
Unless of course, you're a silly European, so then prefer ALAW
G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority
Okay, well, signed linear is easy to translate into other stuff
G.726 is standard ADPCM, in RFC3551 packing order
G.726 is standard ADPCM, in AAL2 packing order
ADPCM has great sound quality and is still pretty easy to translate
Okay, we're down to vocoders now, so pick GSM because it's small and easier to translate and sounds pretty good
iLBC is not too bad
Speex is free, but computationally more expensive than GSM
Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough to use it
G.729a is faster than 723 and slightly less expensive
Down to G.723.1 which is proprietary but at least designed for voice
Definition at line 712 of file channel.c.
References ARRAY_LEN, AST_FORMAT_ADPCM, AST_FORMAT_ALAW, AST_FORMAT_AUDIO_MASK, AST_FORMAT_G722, AST_FORMAT_G723_1, AST_FORMAT_G726, AST_FORMAT_G726_AAL2, AST_FORMAT_G729A, AST_FORMAT_GSM, AST_FORMAT_ILBC, AST_FORMAT_LPC10, AST_FORMAT_SLINEAR, AST_FORMAT_SLINEAR16, AST_FORMAT_SPEEX, AST_FORMAT_ULAW, ast_log(), LOG_WARNING, and prefs.
Referenced by __oh323_new(), agent_call(), ast_codec_choose(), ast_iax2_new(), ast_speech_new(), builtin_atxfer(), echo_exec(), findmeexec(), gtalk_new(), handle_open_receive_channel_ack_message(), iax2_request(), jingle_new(), local_new(), login_exec(), mgcp_new(), sip_new(), skinny_new(), skinny_set_rtp_peer(), socket_process(), start_rtp(), transmit_connect(), and unistim_new().
00713 { 00714 /* This just our opinion, expressed in code. We are asked to choose 00715 the best codec to use, given no information */ 00716 int x; 00717 static const int prefs[] = 00718 { 00719 /*! Okay, ulaw is used by all telephony equipment, so start with it */ 00720 AST_FORMAT_ULAW, 00721 /*! Unless of course, you're a silly European, so then prefer ALAW */ 00722 AST_FORMAT_ALAW, 00723 /*! G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority */ 00724 AST_FORMAT_G722, 00725 /*! Okay, well, signed linear is easy to translate into other stuff */ 00726 AST_FORMAT_SLINEAR16, 00727 AST_FORMAT_SLINEAR, 00728 /*! G.726 is standard ADPCM, in RFC3551 packing order */ 00729 AST_FORMAT_G726, 00730 /*! G.726 is standard ADPCM, in AAL2 packing order */ 00731 AST_FORMAT_G726_AAL2, 00732 /*! ADPCM has great sound quality and is still pretty easy to translate */ 00733 AST_FORMAT_ADPCM, 00734 /*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to 00735 translate and sounds pretty good */ 00736 AST_FORMAT_GSM, 00737 /*! iLBC is not too bad */ 00738 AST_FORMAT_ILBC, 00739 /*! Speex is free, but computationally more expensive than GSM */ 00740 AST_FORMAT_SPEEX, 00741 /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough 00742 to use it */ 00743 AST_FORMAT_LPC10, 00744 /*! G.729a is faster than 723 and slightly less expensive */ 00745 AST_FORMAT_G729A, 00746 /*! Down to G.723.1 which is proprietary but at least designed for voice */ 00747 AST_FORMAT_G723_1, 00748 }; 00749 00750 /* Strip out video */ 00751 fmts &= AST_FORMAT_AUDIO_MASK; 00752 00753 /* Find the first preferred codec in the format given */ 00754 for (x = 0; x < ARRAY_LEN(prefs); x++) { 00755 if (fmts & prefs[x]) 00756 return prefs[x]; 00757 } 00758 00759 ast_log(LOG_WARNING, "Don't know any of 0x%x formats\n", fmts); 00760 00761 return 0; 00762 }
struct ast_channel* ast_bridged_channel | ( | struct ast_channel * | chan | ) |
Find bridged channel.
chan | Current channel |
Definition at line 4725 of file channel.c.
References ast_channel::_bridge, ast_channel_tech::bridged_channel, chanlist::chan, and ast_channel::tech.
Referenced by __dahdi_exception(), action_agents(), action_coreshowchannels(), agents_show(), agents_show_online(), ast_bridge_call(), ast_channel_masquerade(), ast_park_call_full(), ast_rtp_set_vars(), attempt_transfer(), cb_events(), channel_spy(), check_bridge(), common_exec(), console_transfer(), create_jb(), dahdi_handle_event(), dahdi_hangup(), export_aoc_vars(), get_refer_info(), handle_chanlist(), handle_hd_hf(), handle_invite_replaces(), handle_request(), handle_request_bye(), handle_request_info(), handle_request_refer(), handle_showchan(), handle_soft_key_event_message(), handle_stimulus_message(), key_call(), key_dial_page(), local_attended_transfer(), mgcp_hangup(), mgcp_ss(), misdn_attempt_transfer(), mixmonitor_thread(), schedule_delivery(), sip_hangup(), sip_set_rtp_peer(), skinny_transfer(), socket_process(), ss_thread(), start_spying(), startmon(), TransferCallStep1(), and unistim_hangup().
04726 { 04727 struct ast_channel *bridged; 04728 bridged = chan->_bridge; 04729 if (bridged && bridged->tech->bridged_channel) 04730 bridged = bridged->tech->bridged_channel(chan, bridged); 04731 return bridged; 04732 }
int ast_call | ( | struct ast_channel * | chan, | |
char * | addr, | |||
int | timeout | |||
) |
Make a call.
chan | which channel to make the call on | |
addr | destination of the call | |
timeout | time to wait on for connect Place a call, take no longer than timeout ms. |
Definition at line 4035 of file channel.c.
References AST_CDR_FLAG_DIALED, ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, ast_set_flag, ast_test_flag, ast_channel_tech::call, ast_channel::cdr, chanlist::chan, and ast_channel::tech.
Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), ast_feature_request_and_dial(), attempt_reconnect(), begin_dial_channel(), connect_link(), dial_exec_full(), do_forward(), do_idle_thread(), findmeexec(), ring_entry(), and rpt().
04036 { 04037 /* Place an outgoing call, but don't wait any longer than timeout ms before returning. 04038 If the remote end does not answer within the timeout, then do NOT hang up, but 04039 return anyway. */ 04040 int res = -1; 04041 /* Stop if we're a zombie or need a soft hangup */ 04042 ast_channel_lock(chan); 04043 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) { 04044 if (chan->cdr) { 04045 ast_set_flag(chan->cdr, AST_CDR_FLAG_DIALED); 04046 } 04047 if (chan->tech->call) 04048 res = chan->tech->call(chan, addr, timeout); 04049 ast_set_flag(chan, AST_FLAG_OUTGOING); 04050 } 04051 ast_channel_unlock(chan); 04052 return res; 04053 }
struct ast_channel* ast_call_forward | ( | struct ast_channel * | caller, | |
struct ast_channel * | orig, | |||
int * | timeout, | |||
int | format, | |||
struct outgoing_helper * | oh, | |||
int * | outstate | |||
) |
Forwards a call to a new channel specified by the original channel's call_forward str. If possible, the new forwarded channel is created and returned while the original one is terminated.
caller | in channel that requested orig | |
orig | channel being replaced by the call forward channel | |
timeout | maximum amount of time to wait for setup of new forward channel | |
format | requested channel format | |
oh | outgoing helper used with original channel | |
outstate | reason why unsuccessful (if uncuccessful) |
Definition at line 3760 of file channel.c.
References outgoing_helper::account, accountcode, ast_channel::accountcode, ast_call(), AST_CDR_FLAG_ORIGINATED, ast_cdr_setaccount(), ast_channel_datastore_inherit(), ast_channel_inherit_variables(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_copy_flags, ast_copy_string(), ast_hangup(), ast_log(), ast_request(), ast_set_callerid(), ast_set_variables(), ast_string_field_set, ast_strlen_zero(), ast_channel::call_forward, ast_channel::cdr, CHANNEL_DEADLOCK_AVOIDANCE, ast_channel::cid, outgoing_helper::cid_name, ast_callerid::cid_name, outgoing_helper::cid_num, ast_callerid::cid_num, ast_channel::context, handle_cause(), LOG_NOTICE, outgoing_helper::parent_channel, pbx_builtin_getvar_helper(), S_OR, type, and outgoing_helper::vars.
Referenced by __ast_request_and_dial(), and ast_feature_request_and_dial().
03761 { 03762 char tmpchan[256]; 03763 struct ast_channel *new = NULL; 03764 char *data, *type; 03765 int cause = 0; 03766 03767 /* gather data and request the new forward channel */ 03768 ast_copy_string(tmpchan, orig->call_forward, sizeof(tmpchan)); 03769 if ((data = strchr(tmpchan, '/'))) { 03770 *data++ = '\0'; 03771 type = tmpchan; 03772 } else { 03773 const char *forward_context; 03774 ast_channel_lock(orig); 03775 forward_context = pbx_builtin_getvar_helper(orig, "FORWARD_CONTEXT"); 03776 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", orig->call_forward, S_OR(forward_context, orig->context)); 03777 ast_channel_unlock(orig); 03778 data = tmpchan; 03779 type = "Local"; 03780 } 03781 if (!(new = ast_request(type, format, data, &cause))) { 03782 ast_log(LOG_NOTICE, "Unable to create channel for call forward to '%s/%s' (cause = %d)\n", type, data, cause); 03783 handle_cause(cause, outstate); 03784 ast_hangup(orig); 03785 return NULL; 03786 } 03787 03788 /* Copy/inherit important information into new channel */ 03789 if (oh) { 03790 if (oh->vars) { 03791 ast_set_variables(new, oh->vars); 03792 } 03793 if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) { 03794 ast_set_callerid(new, oh->cid_num, oh->cid_name, oh->cid_num); 03795 } 03796 if (oh->parent_channel) { 03797 ast_channel_inherit_variables(oh->parent_channel, new); 03798 ast_channel_datastore_inherit(oh->parent_channel, new); 03799 } 03800 if (oh->account) { 03801 ast_cdr_setaccount(new, oh->account); 03802 } 03803 } else if (caller) { /* no outgoing helper so use caller if avaliable */ 03804 ast_channel_inherit_variables(caller, new); 03805 ast_channel_datastore_inherit(caller, new); 03806 } 03807 03808 ast_channel_lock(orig); 03809 while (ast_channel_trylock(new)) { 03810 CHANNEL_DEADLOCK_AVOIDANCE(orig); 03811 } 03812 ast_copy_flags(new->cdr, orig->cdr, AST_CDR_FLAG_ORIGINATED); 03813 ast_string_field_set(new, accountcode, orig->accountcode); 03814 if (!ast_strlen_zero(orig->cid.cid_num) && !ast_strlen_zero(new->cid.cid_name)) { 03815 ast_set_callerid(new, orig->cid.cid_num, orig->cid.cid_name, orig->cid.cid_num); 03816 } 03817 ast_channel_unlock(new); 03818 ast_channel_unlock(orig); 03819 03820 /* call new channel */ 03821 if ((*timeout = ast_call(new, data, 0))) { 03822 ast_log(LOG_NOTICE, "Unable to call forward to channel %s/%s\n", type, (char *)data); 03823 ast_hangup(orig); 03824 ast_hangup(new); 03825 return NULL; 03826 } 03827 ast_hangup(orig); 03828 03829 return new; 03830 }
void ast_cancel_shutdown | ( | void | ) |
Cancel a shutdown in progress.
Cancels an existing shutdown and returns to normal operation
Definition at line 510 of file channel.c.
Referenced by handle_abort_shutdown().
00511 { 00512 shutting_down = 0; 00513 }
const char* ast_cause2str | ( | int | state | ) |
Gives the string form of a given hangup cause.
state | cause to get the description of Give a name to a cause code Returns the text form of the binary cause code given |
Definition at line 630 of file channel.c.
References ARRAY_LEN, causes, and ast_cause::desc.
Referenced by __transmit_response(), ast_do_masquerade(), ast_hangup(), dial_exec_full(), findmeexec(), sip_hangup(), and transmit_request_with_auth().
00631 { 00632 int x; 00633 00634 for (x = 0; x < ARRAY_LEN(causes); x++) { 00635 if (causes[x].cause == cause) 00636 return causes[x].desc; 00637 } 00638 00639 return "Unknown"; 00640 }
void ast_change_name | ( | struct ast_channel * | chan, | |
char * | newname | |||
) |
Change channel name.
Definition at line 4288 of file channel.c.
References ast_string_field_set, chanlist::chan, EVENT_FLAG_CALL, manager_event, ast_channel::name, name, and ast_channel::uniqueid.
Referenced by update_name().
04289 { 04290 manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", chan->name, newname, chan->uniqueid); 04291 ast_string_field_set(chan, name, newname); 04292 }
struct ast_channel * ast_channel_alloc | ( | int | needqueue, | |
int | state, | |||
const char * | cid_num, | |||
const char * | cid_name, | |||
const char * | acctcode, | |||
const char * | exten, | |||
const char * | context, | |||
const int | amaflag, | |||
const char * | name_fmt, | |||
... | ||||
) |
Definition at line 5872 of file channel.c.
References __ast_channel_alloc_ap().
05876 { 05877 va_list ap1, ap2; 05878 struct ast_channel *result; 05879 05880 05881 va_start(ap1, name_fmt); 05882 va_start(ap2, name_fmt); 05883 result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context, 05884 amaflag, __FILE__, __LINE__, __FUNCTION__, name_fmt, ap1, ap2); 05885 va_end(ap1); 05886 va_end(ap2); 05887 05888 return result; 05889 }
enum ast_bridge_result ast_channel_bridge | ( | struct ast_channel * | c0, | |
struct ast_channel * | c1, | |||
struct ast_bridge_config * | config, | |||
struct ast_frame ** | fo, | |||
struct ast_channel ** | rc | |||
) |
Bridge two channels together.
Bridge two channels together
c0 | first channel to bridge | |
c1 | second channel to bridge | |
config | config for the channels | |
fo | destination frame(?) | |
rc | destination channel(?) Bridge two channels (c0 and c1) together. If an important frame occurs, we return that frame in rf (remember, it could be NULL) and which channel (0 or 1) in rc |
Definition at line 5048 of file channel.c.
References ast_channel::_bridge, ast_channel::_softhangup, AST_BRIDGE_COMPLETE, AST_BRIDGE_FAILED, AST_BRIDGE_FAILED_NOWARN, AST_BRIDGE_RETRY, ast_channel_make_compatible(), ast_check_hangup(), ast_check_hangup_locked(), ast_clear_flag, AST_CONTROL_SRCUPDATE, ast_debug, AST_FEATURE_PLAY_WARNING, AST_FEATURE_WARNING_ACTIVE, AST_FLAG_END_DTMF_ONLY, AST_FLAG_NBRIDGE, AST_FLAG_ZOMBIE, ast_generic_bridge(), ast_indicate(), ast_log(), ast_samp2tv(), ast_set_flag, AST_SOFTHANGUP_UNBRIDGE, ast_test_flag, ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvsub(), ast_tvzero(), ast_verb, ast_channel::audiohooks, ast_channel_tech::bridge, bridge_play_sounds(), bridge_playfile(), ast_channel::cid, ast_callerid::cid_num, config, EVENT_FLAG_CALL, ast_channel::generator, LOG_WARNING, manager_bridge_event(), manager_event, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::name, ast_channel::nativeformats, ast_channel::readformat, ast_channel_tech::send_digit_begin, ast_channel::tech, ast_channel::uniqueid, update_bridge_vars(), and ast_channel::writeformat.
Referenced by ast_bridge_call().
05050 { 05051 struct ast_channel *who = NULL; 05052 enum ast_bridge_result res = AST_BRIDGE_COMPLETE; 05053 int nativefailed=0; 05054 int firstpass; 05055 int o0nativeformats; 05056 int o1nativeformats; 05057 long time_left_ms=0; 05058 char caller_warning = 0; 05059 char callee_warning = 0; 05060 05061 if (c0->_bridge) { 05062 ast_log(LOG_WARNING, "%s is already in a bridge with %s\n", 05063 c0->name, c0->_bridge->name); 05064 return -1; 05065 } 05066 if (c1->_bridge) { 05067 ast_log(LOG_WARNING, "%s is already in a bridge with %s\n", 05068 c1->name, c1->_bridge->name); 05069 return -1; 05070 } 05071 05072 /* Stop if we're a zombie or need a soft hangup */ 05073 if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || 05074 ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) 05075 return -1; 05076 05077 *fo = NULL; 05078 firstpass = config->firstpass; 05079 config->firstpass = 0; 05080 05081 if (ast_tvzero(config->start_time)) 05082 config->start_time = ast_tvnow(); 05083 time_left_ms = config->timelimit; 05084 05085 caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING); 05086 callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING); 05087 05088 if (config->start_sound && firstpass) { 05089 if (caller_warning) 05090 bridge_playfile(c0, c1, config->start_sound, time_left_ms / 1000); 05091 if (callee_warning) 05092 bridge_playfile(c1, c0, config->start_sound, time_left_ms / 1000); 05093 } 05094 05095 /* Keep track of bridge */ 05096 c0->_bridge = c1; 05097 c1->_bridge = c0; 05098 05099 05100 o0nativeformats = c0->nativeformats; 05101 o1nativeformats = c1->nativeformats; 05102 05103 if (config->feature_timer && !ast_tvzero(config->nexteventts)) { 05104 config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->feature_timer, 1000)); 05105 } else if (config->timelimit && firstpass) { 05106 config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000)); 05107 if (caller_warning || callee_warning) 05108 config->nexteventts = ast_tvsub(config->nexteventts, ast_samp2tv(config->play_warning, 1000)); 05109 } 05110 05111 if (!c0->tech->send_digit_begin) 05112 ast_set_flag(c1, AST_FLAG_END_DTMF_ONLY); 05113 if (!c1->tech->send_digit_begin) 05114 ast_set_flag(c0, AST_FLAG_END_DTMF_ONLY); 05115 manager_bridge_event(1, 1, c0, c1); 05116 05117 /* Before we enter in and bridge these two together tell them both the source of audio has changed */ 05118 ast_indicate(c0, AST_CONTROL_SRCUPDATE); 05119 ast_indicate(c1, AST_CONTROL_SRCUPDATE); 05120 05121 for (/* ever */;;) { 05122 struct timeval now = { 0, }; 05123 int to; 05124 05125 to = -1; 05126 05127 if (!ast_tvzero(config->nexteventts)) { 05128 now = ast_tvnow(); 05129 to = ast_tvdiff_ms(config->nexteventts, now); 05130 if (to <= 0) { 05131 if (!config->timelimit) { 05132 res = AST_BRIDGE_COMPLETE; 05133 break; 05134 } 05135 to = 0; 05136 } 05137 } 05138 05139 if (config->timelimit) { 05140 time_left_ms = config->timelimit - ast_tvdiff_ms(now, config->start_time); 05141 if (time_left_ms < to) 05142 to = time_left_ms; 05143 05144 if (time_left_ms <= 0) { 05145 if (caller_warning && config->end_sound) 05146 bridge_playfile(c0, c1, config->end_sound, 0); 05147 if (callee_warning && config->end_sound) 05148 bridge_playfile(c1, c0, config->end_sound, 0); 05149 *fo = NULL; 05150 if (who) 05151 *rc = who; 05152 res = 0; 05153 break; 05154 } 05155 05156 if (!to) { 05157 if (time_left_ms >= 5000 && config->warning_sound && config->play_warning && ast_test_flag(config, AST_FEATURE_WARNING_ACTIVE)) { 05158 int t = (time_left_ms + 500) / 1000; /* round to nearest second */ 05159 if (caller_warning) 05160 bridge_playfile(c0, c1, config->warning_sound, t); 05161 if (callee_warning) 05162 bridge_playfile(c1, c0, config->warning_sound, t); 05163 } 05164 if (config->warning_freq && (time_left_ms > (config->warning_freq + 5000))) 05165 config->nexteventts = ast_tvadd(config->nexteventts, ast_samp2tv(config->warning_freq, 1000)); 05166 else 05167 config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000)); 05168 } 05169 ast_clear_flag(config, AST_FEATURE_WARNING_ACTIVE); 05170 } 05171 05172 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) { 05173 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 05174 c0->_softhangup = 0; 05175 if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 05176 c1->_softhangup = 0; 05177 c0->_bridge = c1; 05178 c1->_bridge = c0; 05179 ast_debug(1, "Unbridge signal received. Ending native bridge.\n"); 05180 continue; 05181 } 05182 05183 /* Stop if we're a zombie or need a soft hangup */ 05184 if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || 05185 ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) { 05186 *fo = NULL; 05187 if (who) 05188 *rc = who; 05189 res = 0; 05190 ast_debug(1, "Bridge stops because we're zombie or need a soft hangup: c0=%s, c1=%s, flags: %s,%s,%s,%s\n", 05191 c0->name, c1->name, 05192 ast_test_flag(c0, AST_FLAG_ZOMBIE) ? "Yes" : "No", 05193 ast_check_hangup(c0) ? "Yes" : "No", 05194 ast_test_flag(c1, AST_FLAG_ZOMBIE) ? "Yes" : "No", 05195 ast_check_hangup(c1) ? "Yes" : "No"); 05196 break; 05197 } 05198 05199 update_bridge_vars(c0, c1); 05200 05201 bridge_play_sounds(c0, c1); 05202 05203 if (c0->tech->bridge && 05204 /* if < 1 ms remains use generic bridging for accurate timing */ 05205 (!config->timelimit || to > 1000 || to == 0) && 05206 (c0->tech->bridge == c1->tech->bridge) && 05207 !nativefailed && !c0->monitor && !c1->monitor && 05208 !c0->audiohooks && !c1->audiohooks && 05209 !c0->masq && !c0->masqr && !c1->masq && !c1->masqr) { 05210 int timeoutms = to - 1000 > 0 ? to - 1000 : to; 05211 /* Looks like they share a bridge method and nothing else is in the way */ 05212 ast_set_flag(c0, AST_FLAG_NBRIDGE); 05213 ast_set_flag(c1, AST_FLAG_NBRIDGE); 05214 if ((res = c0->tech->bridge(c0, c1, config->flags, fo, rc, timeoutms)) == AST_BRIDGE_COMPLETE) { 05215 /* \todo XXX here should check that cid_num is not NULL */ 05216 manager_event(EVENT_FLAG_CALL, "Unlink", 05217 "Channel1: %s\r\n" 05218 "Channel2: %s\r\n" 05219 "Uniqueid1: %s\r\n" 05220 "Uniqueid2: %s\r\n" 05221 "CallerID1: %s\r\n" 05222 "CallerID2: %s\r\n", 05223 c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); 05224 ast_debug(1, "Returning from native bridge, channels: %s, %s\n", c0->name, c1->name); 05225 05226 ast_clear_flag(c0, AST_FLAG_NBRIDGE); 05227 ast_clear_flag(c1, AST_FLAG_NBRIDGE); 05228 05229 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 05230 continue; 05231 05232 c0->_bridge = NULL; 05233 c1->_bridge = NULL; 05234 05235 return res; 05236 } else { 05237 ast_clear_flag(c0, AST_FLAG_NBRIDGE); 05238 ast_clear_flag(c1, AST_FLAG_NBRIDGE); 05239 } 05240 switch (res) { 05241 case AST_BRIDGE_RETRY: 05242 if (config->play_warning) { 05243 ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE); 05244 } 05245 continue; 05246 default: 05247 ast_verb(3, "Native bridging %s and %s ended\n", c0->name, c1->name); 05248 /* fallthrough */ 05249 case AST_BRIDGE_FAILED_NOWARN: 05250 nativefailed++; 05251 break; 05252 } 05253 } 05254 05255 if (((c0->writeformat != c1->readformat) || (c0->readformat != c1->writeformat) || 05256 (c0->nativeformats != o0nativeformats) || (c1->nativeformats != o1nativeformats)) && 05257 !(c0->generator || c1->generator)) { 05258 if (ast_channel_make_compatible(c0, c1)) { 05259 ast_log(LOG_WARNING, "Can't make %s and %s compatible\n", c0->name, c1->name); 05260 manager_bridge_event(0, 1, c0, c1); 05261 return AST_BRIDGE_FAILED; 05262 } 05263 o0nativeformats = c0->nativeformats; 05264 o1nativeformats = c1->nativeformats; 05265 } 05266 05267 update_bridge_vars(c0, c1); 05268 05269 res = ast_generic_bridge(c0, c1, config, fo, rc, config->nexteventts); 05270 if (res != AST_BRIDGE_RETRY) { 05271 break; 05272 } else if (config->feature_timer) { 05273 /* feature timer expired but has not been updated, sending to ast_bridge_call to do so */ 05274 break; 05275 } 05276 } 05277 05278 ast_clear_flag(c0, AST_FLAG_END_DTMF_ONLY); 05279 ast_clear_flag(c1, AST_FLAG_END_DTMF_ONLY); 05280 05281 /* Now that we have broken the bridge the source will change yet again */ 05282 ast_indicate(c0, AST_CONTROL_SRCUPDATE); 05283 ast_indicate(c1, AST_CONTROL_SRCUPDATE); 05284 05285 c0->_bridge = NULL; 05286 c1->_bridge = NULL; 05287 05288 /* \todo XXX here should check that cid_num is not NULL */ 05289 manager_event(EVENT_FLAG_CALL, "Unlink", 05290 "Channel1: %s\r\n" 05291 "Channel2: %s\r\n" 05292 "Uniqueid1: %s\r\n" 05293 "Uniqueid2: %s\r\n" 05294 "CallerID1: %s\r\n" 05295 "CallerID2: %s\r\n", 05296 c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); 05297 ast_debug(1, "Bridge stops bridging channels %s and %s\n", c0->name, c1->name); 05298 05299 return res; 05300 }
int ast_channel_cmpwhentohangup | ( | struct ast_channel * | chan, | |
time_t | offset | |||
) |
Compare a offset with the settings of when to hang a channel up.
chan | channel on which to check for hang up | |
offset | offset in seconds from current time |
Definition at line 551 of file channel.c.
References ast_channel_cmpwhentohangup_tv(), and chanlist::chan.
00552 { 00553 struct timeval when = { offset, }; 00554 return ast_channel_cmpwhentohangup_tv(chan, when); 00555 }
int ast_channel_cmpwhentohangup_tv | ( | struct ast_channel * | chan, | |
struct timeval | offset | |||
) |
Compare a offset with the settings of when to hang a channel up.
chan | channel on which to check for hangup | |
offset | offset in seconds and microseconds from current time |
Definition at line 536 of file channel.c.
References ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), chanlist::chan, and ast_channel::whentohangup.
Referenced by ast_channel_cmpwhentohangup().
00537 { 00538 struct timeval whentohangup; 00539 00540 if (ast_tvzero(chan->whentohangup)) 00541 return ast_tvzero(offset) ? 0 : -1; 00542 00543 if (ast_tvzero(offset)) 00544 return 1; 00545 00546 whentohangup = ast_tvadd(offset, ast_tvnow()); 00547 00548 return ast_tvdiff_ms(whentohangup, chan->whentohangup); 00549 }
int ast_channel_datastore_add | ( | struct ast_channel * | chan, | |
struct ast_datastore * | datastore | |||
) |
Add a datastore to a channel.
0 | success | |
non-zero | failure |
Definition at line 1513 of file channel.c.
References AST_LIST_INSERT_HEAD, chanlist::chan, ast_channel::datastores, and ast_datastore::entry.
Referenced by _macro_exec(), acf_iaxvar_write(), add_features_datastores(), add_to_agi(), ast_iax2_new(), audiohook_volume_get(), authenticate_reply(), dial_exec_full(), dundi_query_read(), enable_jack_hook(), enum_query_read(), get_lock(), gosub_exec(), lua_get_state(), pbx_builtin_raise_exception(), setup_chanspy_ds(), setup_inheritance_datastore(), setup_mixmonitor_ds(), setup_transfer_datastore(), shared_write(), smdi_msg_retrieve_read(), socket_process(), speech_create(), speex_write(), try_calling(), and volume_write().
01514 { 01515 int res = 0; 01516 01517 AST_LIST_INSERT_HEAD(&chan->datastores, datastore, entry); 01518 01519 return res; 01520 }
struct ast_datastore* ast_channel_datastore_alloc | ( | const struct ast_datastore_info * | info, | |
const char * | uid | |||
) |
Create a channel data store object.
Definition at line 1486 of file channel.c.
References ast_datastore_alloc, and ast_datastore::info.
01487 { 01488 return ast_datastore_alloc(info, uid); 01489 }
struct ast_datastore* ast_channel_datastore_find | ( | struct ast_channel * | chan, | |
const struct ast_datastore_info * | info, | |||
const char * | uid | |||
) |
Find a datastore on a channel.
The datastore returned from this function must not be used if the reference to the channel is released.
pointer | to the datastore if found | |
NULL | if not found |
Definition at line 1527 of file channel.c.
References AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, chanlist::chan, ast_channel::datastores, ast_datastore::entry, ast_datastore::info, and ast_datastore::uid.
Referenced by _macro_exec(), acf_exception_read(), acf_fetch(), acf_iaxvar_read(), acf_iaxvar_write(), add_agi_cmd(), add_features_datastores(), add_to_agi(), attended_transfer_occurred(), audiohook_volume_callback(), audiohook_volume_get(), builtin_atxfer(), chanspy_ds_free(), dial_exec_full(), disable_jack_hook(), dundi_result_read(), enable_jack_hook(), enum_result_read(), exec_odbcfinish(), find_speech(), func_inheritance_write(), get_agi_cmd(), get_lock(), gosub_exec(), handle_gosub(), iax2_call(), jack_hook_callback(), local_read(), local_write(), lock_fixup(), lua_get_state(), manage_parkinglot(), park_exec_full(), pbx_builtin_raise_exception(), pop_exec(), queue_transfer_fixup(), return_exec(), shared_read(), shared_write(), smdi_msg_read(), speech_background(), speech_destroy(), speex_callback(), speex_read(), speex_write(), stop_mixmonitor_exec(), try_calling(), unlock_read(), volume_callback(), and volume_write().
01528 { 01529 struct ast_datastore *datastore = NULL; 01530 01531 if (info == NULL) 01532 return NULL; 01533 01534 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore, entry) { 01535 if (datastore->info != info) { 01536 continue; 01537 } 01538 01539 if (uid == NULL) { 01540 /* matched by type only */ 01541 break; 01542 } 01543 01544 if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) { 01545 /* Matched by type AND uid */ 01546 break; 01547 } 01548 } 01549 AST_LIST_TRAVERSE_SAFE_END; 01550 01551 return datastore; 01552 }
int ast_channel_datastore_free | ( | struct ast_datastore * | datastore | ) |
Free a channel data store object.
Definition at line 1491 of file channel.c.
References ast_datastore_free().
01492 { 01493 return ast_datastore_free(datastore); 01494 }
int ast_channel_datastore_inherit | ( | struct ast_channel * | from, | |
struct ast_channel * | to | |||
) |
Inherit datastores from a parent to a child.
Definition at line 1496 of file channel.c.
References ast_datastore_alloc, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_datastore::data, DATASTORE_INHERIT_FOREVER, ast_channel::datastores, ast_datastore_info::duplicate, ast_datastore::entry, ast_datastore::info, ast_datastore::inheritance, and ast_datastore::uid.
Referenced by __ast_request_and_dial(), ast_call_forward(), dial_exec_full(), do_forward(), findmeexec(), local_call(), and ring_entry().
01497 { 01498 struct ast_datastore *datastore = NULL, *datastore2; 01499 01500 AST_LIST_TRAVERSE(&from->datastores, datastore, entry) { 01501 if (datastore->inheritance > 0) { 01502 datastore2 = ast_datastore_alloc(datastore->info, datastore->uid); 01503 if (datastore2) { 01504 datastore2->data = datastore->info->duplicate ? datastore->info->duplicate(datastore->data) : NULL; 01505 datastore2->inheritance = datastore->inheritance == DATASTORE_INHERIT_FOREVER ? DATASTORE_INHERIT_FOREVER : datastore->inheritance - 1; 01506 AST_LIST_INSERT_TAIL(&to->datastores, datastore2, entry); 01507 } 01508 } 01509 } 01510 return 0; 01511 }
int ast_channel_datastore_remove | ( | struct ast_channel * | chan, | |
struct ast_datastore * | datastore | |||
) |
Remove a datastore from a channel.
0 | success | |
non-zero | failure |
Definition at line 1522 of file channel.c.
References AST_LIST_REMOVE, chanlist::chan, ast_channel::datastores, and ast_datastore::entry.
Referenced by acf_fetch(), chanspy_ds_free(), dial_exec_full(), disable_jack_hook(), exec_odbcfinish(), lua_get_state(), queue_transfer_fixup(), speech_background(), speech_destroy(), speex_write(), stop_mixmonitor_exec(), and try_calling().
01523 { 01524 return AST_LIST_REMOVE(&chan->datastores, datastore, entry) ? 0 : -1; 01525 }
int ast_channel_defer_dtmf | ( | struct ast_channel * | chan | ) |
Set defer DTMF flag on channel.
Defer DTMF so that you only read things like hangups and audio. Returns non-zero if channel was already DTMF-deferred or 0 if channel is just now being DTMF-deferred
Definition at line 1147 of file channel.c.
References AST_FLAG_DEFER_DTMF, ast_set_flag, ast_test_flag, and chanlist::chan.
Referenced by find_cache().
01148 { 01149 int pre = 0; 01150 01151 if (chan) { 01152 pre = ast_test_flag(chan, AST_FLAG_DEFER_DTMF); 01153 ast_set_flag(chan, AST_FLAG_DEFER_DTMF); 01154 } 01155 return pre; 01156 }
int ast_channel_early_bridge | ( | struct ast_channel * | c0, | |
struct ast_channel * | c1 | |||
) |
Bridge two channels together (early).
Bridge two channels together (early)
c0 | first channel to bridge | |
c1 | second channel to bridge Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet. |
Definition at line 4950 of file channel.c.
References ast_channel_tech::early_bridge, and ast_channel::tech.
Referenced by dial_exec_full(), and wait_for_answer().
04951 { 04952 /* Make sure we can early bridge, if not error out */ 04953 if (!c0->tech->early_bridge || (c1 && (!c1->tech->early_bridge || c0->tech->early_bridge != c1->tech->early_bridge))) 04954 return -1; 04955 04956 return c0->tech->early_bridge(c0, c1); 04957 }
void ast_channel_free | ( | struct ast_channel * | chan | ) |
Free a channel structure.
Definition at line 1371 of file channel.c.
References ast_channel::alertpipe, ast_app_group_discard(), ast_cdr_discard(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_unlock, ast_copy_string(), ast_datastore_free(), ast_debug, AST_DEVICE_UNKNOWN, ast_devstate_changed_literal(), AST_FLAG_IN_CHANNEL_LIST, ast_free, ast_frfree, ast_jb_destroy(), AST_LIST_REMOVE_HEAD, ast_log(), AST_MAX_FDS, ast_moh_cleanup(), ast_mutex_destroy(), AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_string_field_free_memory, ast_test_flag, ast_timer_close(), ast_translator_free_path(), ast_var_delete(), ast_channel::cdr, chanlist::chan, ast_channel::cid, ast_channel::datastores, ast_datastore::entry, f, free, free_cid(), ast_channel::lock_dont_use, LOG_WARNING, ast_channel::monitor, ast_channel::music_state, name, ast_channel::name, ast_channel::pbx, ast_channel::readq, ast_channel::readtrans, ast_channel::sched, sched_context_destroy(), ast_channel_monitor::stop, ast_channel::tech_pvt, ast_channel::timer, ast_channel::varshead, and ast_channel::writetrans.
Referenced by acf_odbc_write(), action_getvar(), agent_cleanup(), agent_new(), ast_do_masquerade(), ast_hangup(), ast_iax2_new(), ast_pbx_outgoing_cdr_failed(), gtalk_newcall(), local_new(), make_email_file(), pbx_substitute_variables_helper_full(), rotate_file(), sendmail(), and sendpage().
01372 { 01373 int fd; 01374 #ifdef HAVE_EPOLL 01375 int i; 01376 #endif 01377 struct ast_var_t *vardata; 01378 struct ast_frame *f; 01379 struct varshead *headp; 01380 struct ast_datastore *datastore = NULL; 01381 char name[AST_CHANNEL_NAME], *dashptr; 01382 int inlist; 01383 01384 headp=&chan->varshead; 01385 01386 inlist = ast_test_flag(chan, AST_FLAG_IN_CHANNEL_LIST); 01387 if (inlist) { 01388 AST_RWLIST_WRLOCK(&channels); 01389 if (!AST_RWLIST_REMOVE(&channels, chan, chan_list)) { 01390 ast_debug(1, "Unable to find channel in list to free. Assuming it has already been done.\n"); 01391 } 01392 /* Lock and unlock the channel just to be sure nobody has it locked still 01393 due to a reference retrieved from the channel list. */ 01394 ast_channel_lock(chan); 01395 ast_channel_unlock(chan); 01396 } 01397 01398 /* Get rid of each of the data stores on the channel */ 01399 ast_channel_lock(chan); 01400 while ((datastore = AST_LIST_REMOVE_HEAD(&chan->datastores, entry))) 01401 /* Free the data store */ 01402 ast_datastore_free(datastore); 01403 ast_channel_unlock(chan); 01404 01405 /* Lock and unlock the channel just to be sure nobody has it locked still 01406 due to a reference that was stored in a datastore. (i.e. app_chanspy) */ 01407 ast_channel_lock(chan); 01408 ast_channel_unlock(chan); 01409 01410 if (chan->tech_pvt) { 01411 ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name); 01412 ast_free(chan->tech_pvt); 01413 } 01414 01415 if (chan->sched) 01416 sched_context_destroy(chan->sched); 01417 01418 ast_copy_string(name, chan->name, sizeof(name)); 01419 if ((dashptr = strrchr(name, '-'))) { 01420 *dashptr = '\0'; 01421 } 01422 01423 /* Stop monitoring */ 01424 if (chan->monitor) 01425 chan->monitor->stop( chan, 0 ); 01426 01427 /* If there is native format music-on-hold state, free it */ 01428 if (chan->music_state) 01429 ast_moh_cleanup(chan); 01430 01431 /* Free translators */ 01432 if (chan->readtrans) 01433 ast_translator_free_path(chan->readtrans); 01434 if (chan->writetrans) 01435 ast_translator_free_path(chan->writetrans); 01436 if (chan->pbx) 01437 ast_log(LOG_WARNING, "PBX may not have been terminated properly on '%s'\n", chan->name); 01438 free_cid(&chan->cid); 01439 /* Close pipes if appropriate */ 01440 if ((fd = chan->alertpipe[0]) > -1) 01441 close(fd); 01442 if ((fd = chan->alertpipe[1]) > -1) 01443 close(fd); 01444 if (chan->timer) { 01445 ast_timer_close(chan->timer); 01446 } 01447 #ifdef HAVE_EPOLL 01448 for (i = 0; i < AST_MAX_FDS; i++) { 01449 if (chan->epfd_data[i]) 01450 free(chan->epfd_data[i]); 01451 } 01452 close(chan->epfd); 01453 #endif 01454 while ((f = AST_LIST_REMOVE_HEAD(&chan->readq, frame_list))) 01455 ast_frfree(f); 01456 01457 /* loop over the variables list, freeing all data and deleting list items */ 01458 /* no need to lock the list, as the channel is already locked */ 01459 01460 while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries))) 01461 ast_var_delete(vardata); 01462 01463 ast_app_group_discard(chan); 01464 01465 /* Destroy the jitterbuffer */ 01466 ast_jb_destroy(chan); 01467 01468 if (chan->cdr) { 01469 ast_cdr_discard(chan->cdr); 01470 chan->cdr = NULL; 01471 } 01472 01473 ast_mutex_destroy(&chan->lock_dont_use); 01474 01475 ast_string_field_free_memory(chan); 01476 ast_free(chan); 01477 if (inlist) 01478 AST_RWLIST_UNLOCK(&channels); 01479 01480 /* Queue an unknown state, because, while we know that this particular 01481 * instance is dead, we don't know the state of all other possible 01482 * instances. */ 01483 ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, name); 01484 }
void ast_channel_inherit_variables | ( | const struct ast_channel * | parent, | |
struct ast_channel * | child | |||
) |
Inherits channel variable from parent to child channel.
parent | Parent channel | |
child | Child channel |
Definition at line 4294 of file channel.c.
References ast_debug, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_var_assign(), ast_var_full_name(), ast_var_name(), ast_var_value(), ast_var_t::entries, and ast_channel::varshead.
Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), ast_feature_request_and_dial(), begin_dial_channel(), dial_exec_full(), do_forward(), findmeexec(), and ring_entry().
04295 { 04296 struct ast_var_t *current, *newvar; 04297 const char *varname; 04298 04299 AST_LIST_TRAVERSE(&parent->varshead, current, entries) { 04300 int vartype = 0; 04301 04302 varname = ast_var_full_name(current); 04303 if (!varname) 04304 continue; 04305 04306 if (varname[0] == '_') { 04307 vartype = 1; 04308 if (varname[1] == '_') 04309 vartype = 2; 04310 } 04311 04312 switch (vartype) { 04313 case 1: 04314 newvar = ast_var_assign(&varname[1], ast_var_value(current)); 04315 if (newvar) { 04316 AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries); 04317 ast_debug(1, "Copying soft-transferable variable %s.\n", ast_var_name(newvar)); 04318 } 04319 break; 04320 case 2: 04321 newvar = ast_var_assign(varname, ast_var_value(current)); 04322 if (newvar) { 04323 AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries); 04324 ast_debug(1, "Copying hard-transferable variable %s.\n", ast_var_name(newvar)); 04325 } 04326 break; 04327 default: 04328 ast_debug(1, "Not copying variable %s.\n", ast_var_name(current)); 04329 break; 04330 } 04331 } 04332 }
int ast_channel_make_compatible | ( | struct ast_channel * | c0, | |
struct ast_channel * | c1 | |||
) |
Makes two channel formats compatible.
c0 | first channel to make compatible | |
c1 | other channel to make compatible Set two channels to compatible formats -- call before ast_channel_bridge in general . |
Definition at line 4192 of file channel.c.
References ast_channel_make_compatible_helper(), and chanlist::chan.
Referenced by action_bridge(), app_exec(), ast_channel_bridge(), bridge_exec(), check_compat(), dial_exec_full(), do_forward(), park_exec_full(), and wait_for_answer().
04193 { 04194 /* Some callers do not check return code, and we must try to set all call legs correctly */ 04195 int rc = 0; 04196 04197 /* Set up translation from the chan to the peer */ 04198 rc = ast_channel_make_compatible_helper(chan, peer); 04199 04200 if (rc < 0) 04201 return rc; 04202 04203 /* Set up translation from the peer to the chan */ 04204 rc = ast_channel_make_compatible_helper(peer, chan); 04205 04206 return rc; 04207 }
static int ast_channel_make_compatible_helper | ( | struct ast_channel * | from, | |
struct ast_channel * | to | |||
) | [static] |
Set up translation from one channel to another.
Definition at line 4151 of file channel.c.
References AST_FORMAT_AUDIO_MASK, AST_FORMAT_SLINEAR, ast_log(), ast_opt_transcode_via_slin, ast_set_read_format(), ast_set_write_format(), ast_translate_path_steps(), ast_translator_best_choice(), LOG_WARNING, ast_channel::name, ast_channel::nativeformats, ast_channel::readformat, and ast_channel::writeformat.
Referenced by ast_channel_make_compatible().
04152 { 04153 int src; 04154 int dst; 04155 04156 if (from->readformat == to->writeformat && from->writeformat == to->readformat) { 04157 /* Already compatible! Moving on ... */ 04158 return 0; 04159 } 04160 04161 /* Set up translation from the 'from' channel to the 'to' channel */ 04162 src = from->nativeformats; 04163 dst = to->nativeformats; 04164 04165 /* If there's no audio in this call, don't bother with trying to find a translation path */ 04166 if ((src & AST_FORMAT_AUDIO_MASK) == 0 || (dst & AST_FORMAT_AUDIO_MASK) == 0) 04167 return 0; 04168 04169 if (ast_translator_best_choice(&dst, &src) < 0) { 04170 ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", from->name, src, to->name, dst); 04171 return -1; 04172 } 04173 04174 /* if the best path is not 'pass through', then 04175 transcoding is needed; if desired, force transcode path 04176 to use SLINEAR between channels, but only if there is 04177 no direct conversion available */ 04178 if ((src != dst) && ast_opt_transcode_via_slin && 04179 (ast_translate_path_steps(dst, src) != 1)) 04180 dst = AST_FORMAT_SLINEAR; 04181 if (ast_set_read_format(from, dst) < 0) { 04182 ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", from->name, dst); 04183 return -1; 04184 } 04185 if (ast_set_write_format(to, dst) < 0) { 04186 ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", to->name, dst); 04187 return -1; 04188 } 04189 return 0; 04190 }
int ast_channel_masquerade | ( | struct ast_channel * | original, | |
struct ast_channel * | clone | |||
) |
Weird function made for call transfers.
original | channel to make a copy of | |
clone | copy of the original channel |
Definition at line 4209 of file channel.c.
References ast_channel::_bridge, ast_bridged_channel(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_debug, ast_log(), ast_null_frame, ast_queue_frame(), ast_channel_tech::get_base_channel, LOG_WARNING, ast_channel::masq, ast_channel::masqr, ast_channel::name, and ast_channel::tech.
Referenced by ast_async_goto(), ast_pickup_call(), attempt_transfer(), builtin_atxfer(), check_availability(), check_bridge(), check_goto_on_transfer(), do_bridge_masquerade(), handle_invite_replaces(), iax_park(), masq_park_call(), misdn_attempt_transfer(), pickup_do(), sip_park(), and skinny_transfer().
04210 { 04211 int res = -1; 04212 struct ast_channel *final_orig, *final_clone, *base; 04213 04214 retrymasq: 04215 final_orig = original; 04216 final_clone = clonechan; 04217 04218 ast_channel_lock(original); 04219 while (ast_channel_trylock(clonechan)) { 04220 ast_channel_unlock(original); 04221 usleep(1); 04222 ast_channel_lock(original); 04223 } 04224 04225 /* each of these channels may be sitting behind a channel proxy (i.e. chan_agent) 04226 and if so, we don't really want to masquerade it, but its proxy */ 04227 if (original->_bridge && (original->_bridge != ast_bridged_channel(original)) && (original->_bridge->_bridge != original)) 04228 final_orig = original->_bridge; 04229 04230 if (clonechan->_bridge && (clonechan->_bridge != ast_bridged_channel(clonechan)) && (clonechan->_bridge->_bridge != clonechan)) 04231 final_clone = clonechan->_bridge; 04232 04233 if (final_clone->tech->get_base_channel && (base = final_clone->tech->get_base_channel(final_clone))) { 04234 final_clone = base; 04235 } 04236 04237 if ((final_orig != original) || (final_clone != clonechan)) { 04238 /* Lots and lots of deadlock avoidance. The main one we're competing with 04239 * is ast_write(), which locks channels recursively, when working with a 04240 * proxy channel. */ 04241 if (ast_channel_trylock(final_orig)) { 04242 ast_channel_unlock(clonechan); 04243 ast_channel_unlock(original); 04244 goto retrymasq; 04245 } 04246 if (ast_channel_trylock(final_clone)) { 04247 ast_channel_unlock(final_orig); 04248 ast_channel_unlock(clonechan); 04249 ast_channel_unlock(original); 04250 goto retrymasq; 04251 } 04252 ast_channel_unlock(clonechan); 04253 ast_channel_unlock(original); 04254 original = final_orig; 04255 clonechan = final_clone; 04256 } 04257 04258 if (original == clonechan) { 04259 ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name); 04260 ast_channel_unlock(clonechan); 04261 ast_channel_unlock(original); 04262 return -1; 04263 } 04264 04265 ast_debug(1, "Planning to masquerade channel %s into the structure of %s\n", 04266 clonechan->name, original->name); 04267 if (original->masq) { 04268 ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", 04269 original->masq->name, original->name); 04270 } else if (clonechan->masqr) { 04271 ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", 04272 clonechan->name, clonechan->masqr->name); 04273 } else { 04274 original->masq = clonechan; 04275 clonechan->masqr = original; 04276 ast_queue_frame(original, &ast_null_frame); 04277 ast_queue_frame(clonechan, &ast_null_frame); 04278 ast_debug(1, "Done planning to masquerade channel %s into the structure of %s\n", clonechan->name, original->name); 04279 res = 0; 04280 } 04281 04282 ast_channel_unlock(clonechan); 04283 ast_channel_unlock(original); 04284 04285 return res; 04286 }
int ast_channel_queryoption | ( | struct ast_channel * | channel, | |
int | option, | |||
void * | data, | |||
int * | datalen, | |||
int | block | |||
) |
Query the value of an option Works similarly to setoption except only reads the options.
Definition at line 5316 of file channel.c.
References ast_log(), chan, errno, LOG_ERROR, ast_channel_tech::queryoption, and ast_channel::tech.
Referenced by ast_channel_get_t38_state().
05317 { 05318 if (!chan->tech->queryoption) { 05319 errno = ENOSYS; 05320 return -1; 05321 } 05322 05323 if (block) 05324 ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n"); 05325 05326 return chan->tech->queryoption(chan, option, data, datalen); 05327 }
const char* ast_channel_reason2str | ( | int | reason | ) |
return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
reason | The integer argument, usually taken from AST_CONTROL_ macros |
Definition at line 3724 of file channel.c.
References AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, AST_CONTROL_RING, and AST_CONTROL_RINGING.
Referenced by attempt_thread().
03725 { 03726 switch (reason) /* the following appear to be the only ones actually returned by request_and_dial */ 03727 { 03728 case 0: 03729 return "Call Failure (not BUSY, and not NO_ANSWER, maybe Circuit busy or down?)"; 03730 case AST_CONTROL_HANGUP: 03731 return "Hangup"; 03732 case AST_CONTROL_RING: 03733 return "Local Ring"; 03734 case AST_CONTROL_RINGING: 03735 return "Remote end Ringing"; 03736 case AST_CONTROL_ANSWER: 03737 return "Remote end has Answered"; 03738 case AST_CONTROL_BUSY: 03739 return "Remote end is Busy"; 03740 case AST_CONTROL_CONGESTION: 03741 return "Congestion (circuits busy)"; 03742 default: 03743 return "Unknown Reason!!"; 03744 } 03745 }
int ast_channel_register | ( | const struct ast_channel_tech * | tech | ) |
Register a channel technology (a new channel driver) Called by a channel module to register the kind of channels it supports.
tech | Structure defining channel technology or "type" |
Definition at line 558 of file channel.c.
References ast_calloc, ast_debug, AST_LIST_INSERT_HEAD, AST_LIST_TRAVERSE, ast_log(), AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, chanlist::chan, chanlist::list, LOG_WARNING, chanlist::tech, ast_channel::tech, and ast_channel_tech::type.
Referenced by load_module(), and unload_module().
00559 { 00560 struct chanlist *chan; 00561 00562 AST_RWLIST_WRLOCK(&channels); 00563 00564 AST_LIST_TRAVERSE(&backends, chan, list) { 00565 if (!strcasecmp(tech->type, chan->tech->type)) { 00566 ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type); 00567 AST_RWLIST_UNLOCK(&channels); 00568 return -1; 00569 } 00570 } 00571 00572 if (!(chan = ast_calloc(1, sizeof(*chan)))) { 00573 AST_RWLIST_UNLOCK(&channels); 00574 return -1; 00575 } 00576 chan->tech = tech; 00577 AST_LIST_INSERT_HEAD(&backends, chan, list); 00578 00579 ast_debug(1, "Registered handler for '%s' (%s)\n", chan->tech->type, chan->tech->description); 00580 00581 ast_verb(2, "Registered channel type '%s' (%s)\n", chan->tech->type, chan->tech->description); 00582 00583 AST_RWLIST_UNLOCK(&channels); 00584 return 0; 00585 }
int ast_channel_sendhtml | ( | struct ast_channel * | channel, | |
int | subclass, | |||
const char * | data, | |||
int | datalen | |||
) |
Send HTML or URL on link. Returns 0 on success or -1 on failure
Definition at line 4138 of file channel.c.
References chanlist::chan, ast_channel_tech::send_html, and ast_channel::tech.
Referenced by agent_sendhtml(), ast_channel_sendurl(), and wait_for_answer().
04139 { 04140 if (chan->tech->send_html) 04141 return chan->tech->send_html(chan, subclass, data, datalen); 04142 return -1; 04143 }
int ast_channel_sendurl | ( | struct ast_channel * | channel, | |
const char * | url | |||
) |
Send URL on link. Returns 0 on success or -1 on failure
Definition at line 4145 of file channel.c.
References ast_channel_sendhtml(), AST_HTML_URL, and chanlist::chan.
Referenced by dial_exec_full(), and sendurl_exec().
04146 { 04147 return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1); 04148 }
void ast_channel_set_fd | ( | struct ast_channel * | chan, | |
int | which, | |||
int | fd | |||
) |
Set the file descriptor on the channel
Definition at line 1555 of file channel.c.
References ast_calloc, chanlist::chan, ast_channel::data, ast_channel::fds, and free.
Referenced by __ast_channel_alloc_ap(), __oh323_new(), __oh323_rtp_create(), __oh323_update_info(), alsa_new(), ast_deactivate_generator(), ast_do_masquerade(), dahdi_new(), gtalk_new(), jingle_new(), mgcp_new(), misdn_new(), nbs_new(), oss_new(), phone_new(), pri_assign_bearer(), pri_fixup_principle(), setformat(), sip_new(), skinny_new(), start_rtp(), and swap_subs().
01556 { 01557 #ifdef HAVE_EPOLL 01558 struct epoll_event ev; 01559 struct ast_epoll_data *aed = NULL; 01560 01561 if (chan->fds[which] > -1) { 01562 epoll_ctl(chan->epfd, EPOLL_CTL_DEL, chan->fds[which], &ev); 01563 aed = chan->epfd_data[which]; 01564 } 01565 01566 /* If this new fd is valid, add it to the epoll */ 01567 if (fd > -1) { 01568 if (!aed && (!(aed = ast_calloc(1, sizeof(*aed))))) 01569 return; 01570 01571 chan->epfd_data[which] = aed; 01572 aed->chan = chan; 01573 aed->which = which; 01574 01575 ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP; 01576 ev.data.ptr = aed; 01577 epoll_ctl(chan->epfd, EPOLL_CTL_ADD, fd, &ev); 01578 } else if (aed) { 01579 /* We don't have to keep around this epoll data structure now */ 01580 free(aed); 01581 chan->epfd_data[which] = NULL; 01582 } 01583 #endif 01584 chan->fds[which] = fd; 01585 return; 01586 }
int ast_channel_setoption | ( | struct ast_channel * | channel, | |
int | option, | |||
void * | data, | |||
int | datalen, | |||
int | block | |||
) |
Sets an option on a channel.
channel | channel to set options on | |
option | option to change | |
data | data specific to option | |
datalen | length of the data | |
block | blocking or not Set an option on a channel (see frame.h), optionally blocking awaiting the reply Returns 0 on success and -1 on failure |
Definition at line 5303 of file channel.c.
References ast_log(), chan, errno, LOG_ERROR, ast_channel_tech::setoption, and ast_channel::tech.
Referenced by ast_bridge_call(), common_exec(), conf_run(), dahdi_hangup(), dial_exec_full(), func_channel_write(), handle_tddmode(), play_record_review(), reset_volumes(), rpt(), rpt_exec(), set_listen_volume(), set_talk_volume(), and vm_forwardoptions().
05304 { 05305 if (!chan->tech->setoption) { 05306 errno = ENOSYS; 05307 return -1; 05308 } 05309 05310 if (block) 05311 ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n"); 05312 05313 return chan->tech->setoption(chan, option, data, datalen); 05314 }
void ast_channel_setwhentohangup | ( | struct ast_channel * | chan, | |
time_t | offset | |||
) |
Set when to hang a channel up.
chan | channel on which to check for hang up | |
offset | offset in seconds relative to the current time of when to hang up |
Definition at line 529 of file channel.c.
References ast_channel_setwhentohangup_tv(), and chanlist::chan.
00530 { 00531 struct timeval when = { offset, }; 00532 ast_channel_setwhentohangup_tv(chan, when); 00533 }
void ast_channel_setwhentohangup_tv | ( | struct ast_channel * | chan, | |
struct timeval | offset | |||
) |
Set when to hang a channel up.
chan | channel on which to check for hang up | |
offset | offset in seconds and useconds relative to the current time of when to hang up |
Definition at line 522 of file channel.c.
References ast_null_frame, ast_queue_frame(), ast_tvadd(), ast_tvnow(), ast_tvzero(), chanlist::chan, and ast_channel::whentohangup.
Referenced by action_timeout(), ast_channel_setwhentohangup(), handle_autohangup(), and timeout_write().
00523 { 00524 chan->whentohangup = ast_tvzero(offset) ? offset : ast_tvadd(offset, ast_tvnow()); 00525 ast_queue_frame(chan, &ast_null_frame); 00526 return; 00527 }
struct ast_silence_generator* ast_channel_start_silence_generator | ( | struct ast_channel * | chan | ) |
Starts a silence generator on the given channel.
chan | The channel to generate silence on |
The pointer returned by this function must be preserved and passed to ast_channel_stop_silence_generator when you wish to stop the silence generation.
Definition at line 5636 of file channel.c.
References ast_activate_generator(), ast_calloc, ast_debug, AST_FORMAT_SLINEAR, ast_free, ast_log(), ast_set_write_format(), chan, LOG_ERROR, ast_channel::name, ast_silence_generator::old_write_format, silence_generator, and ast_channel::writeformat.
Referenced by __ast_play_and_record(), ast_dtmf_stream(), ast_safe_sleep_conditional(), channel_spy(), TransferCallStep1(), waitfor_exec(), and waitforring_exec().
05637 { 05638 struct ast_silence_generator *state; 05639 05640 if (!(state = ast_calloc(1, sizeof(*state)))) { 05641 return NULL; 05642 } 05643 05644 state->old_write_format = chan->writeformat; 05645 05646 if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) { 05647 ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n"); 05648 ast_free(state); 05649 return NULL; 05650 } 05651 05652 ast_activate_generator(chan, &silence_generator, state); 05653 05654 ast_debug(1, "Started silence generator on '%s'\n", chan->name); 05655 05656 return state; 05657 }
void ast_channel_stop_silence_generator | ( | struct ast_channel * | chan, | |
struct ast_silence_generator * | state | |||
) |
Stops a previously-started silence generator on the given channel.
chan | The channel to operate on | |
state | The ast_silence_generator pointer return by a previous call to ast_channel_start_silence_generator. |
Definition at line 5659 of file channel.c.
References ast_deactivate_generator(), ast_debug, ast_free, ast_log(), ast_set_write_format(), chan, LOG_ERROR, ast_channel::name, and ast_silence_generator::old_write_format.
Referenced by __ast_play_and_record(), ast_dtmf_stream(), ast_safe_sleep_conditional(), channel_spy(), HandleCallOutgoing(), key_dial_page(), unistim_hangup(), waitfor_exec(), and waitforring_exec().
05660 { 05661 if (!state) 05662 return; 05663 05664 ast_deactivate_generator(chan); 05665 05666 ast_debug(1, "Stopped silence generator on '%s'\n", chan->name); 05667 05668 if (ast_set_write_format(chan, state->old_write_format) < 0) 05669 ast_log(LOG_ERROR, "Could not return write format to its original state\n"); 05670 05671 ast_free(state); 05672 }
int ast_channel_supports_html | ( | struct ast_channel * | channel | ) |
Returns 0 if channel does not support HTML or non-zero if it does
Definition at line 4133 of file channel.c.
References chanlist::chan, ast_channel_tech::send_html, and ast_channel::tech.
Referenced by dial_exec_full(), and sendurl_exec().
void ast_channel_undefer_dtmf | ( | struct ast_channel * | chan | ) |
Unset defer DTMF flag on channel.
Undo defer. ast_read will return any dtmf characters that were queued
Definition at line 1159 of file channel.c.
References ast_clear_flag, AST_FLAG_DEFER_DTMF, and chanlist::chan.
Referenced by find_cache(), and rpt_call().
01160 { 01161 if (chan) 01162 ast_clear_flag(chan, AST_FLAG_DEFER_DTMF); 01163 }
void ast_channel_unregister | ( | const struct ast_channel_tech * | tech | ) |
Unregister a channel technology.
tech | Structure defining channel technology or "type" that was previously registered |
Definition at line 588 of file channel.c.
References ast_debug, ast_free, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, chanlist::chan, chanlist::list, chanlist::tech, ast_channel::tech, and ast_channel_tech::type.
Referenced by __unload_module(), load_module(), and unload_module().
00589 { 00590 struct chanlist *chan; 00591 00592 ast_debug(1, "Unregistering channel type '%s'\n", tech->type); 00593 00594 AST_RWLIST_WRLOCK(&channels); 00595 00596 AST_LIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) { 00597 if (chan->tech == tech) { 00598 AST_LIST_REMOVE_CURRENT(list); 00599 ast_free(chan); 00600 ast_verb(2, "Unregistered channel type '%s'\n", tech->type); 00601 break; 00602 } 00603 } 00604 AST_LIST_TRAVERSE_SAFE_END; 00605 00606 AST_RWLIST_UNLOCK(&channels); 00607 }
struct ast_channel* ast_channel_walk_locked | ( | const struct ast_channel * | prev | ) |
Browse channels in use Browse the channels currently in use.
prev | where you want to start in the channel list |
Definition at line 1273 of file channel.c.
References channel_find_locked().
Referenced by action_coreshowchannels(), action_status(), ast_complete_channels(), ast_pickup_call(), conf_exec(), func_channels_read(), handle_chanlist(), handle_core_set_debug_channel(), next_channel(), pickup_by_exten(), and pickup_by_mark().
01274 { 01275 return channel_find_locked(prev, NULL, 0, NULL, NULL); 01276 }
void ast_channels_init | ( | void | ) |
Provided by channel.c
Definition at line 5557 of file channel.c.
References ARRAY_LEN, ast_cli_register_multiple(), and cli_channel.
Referenced by main().
05558 { 05559 ast_cli_register_multiple(cli_channel, ARRAY_LEN(cli_channel)); 05560 }
struct ast_variable* ast_channeltype_list | ( | void | ) |
return an ast_variable list of channeltypes
Definition at line 186 of file channel.c.
References AST_LIST_TRAVERSE, ast_variable_new(), ast_channel_tech::description, chanlist::list, chanlist::tech, ast_channel_tech::type, and var.
00187 { 00188 struct chanlist *cl; 00189 struct ast_variable *var=NULL, *prev = NULL; 00190 AST_LIST_TRAVERSE(&backends, cl, list) { 00191 if (prev) { 00192 if ((prev->next = ast_variable_new(cl->tech->type, cl->tech->description, ""))) 00193 prev = prev->next; 00194 } else { 00195 var = ast_variable_new(cl->tech->type, cl->tech->description, ""); 00196 prev = var; 00197 } 00198 } 00199 return var; 00200 }
int ast_check_hangup | ( | struct ast_channel * | chan | ) |
Check to see if a channel is needing hang up.
chan | channel on which to check for hang up This function determines if the channel is being requested to be hung up. |
Definition at line 462 of file channel.c.
References ast_channel::_softhangup, AST_SOFTHANGUP_TIMEOUT, ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), chanlist::chan, and ast_channel::whentohangup.
Referenced by __ast_pbx_run(), __ast_read(), _macro_exec(), action_redirect(), agent_indicate(), agi_exec(), agi_handle_command(), announce_thread(), ast_bridge_call(), ast_bridge_call_thread(), ast_call(), ast_channel_bridge(), ast_check_hangup_locked(), ast_feature_request_and_dial(), ast_indicate_data(), ast_raw_answer(), ast_readstring_full(), ast_recvtext(), ast_rtp_bridge(), ast_sendtext(), ast_transfer(), ast_udptl_bridge(), ast_waitfordigit_full(), ast_write(), autoservice_run(), bridge_exec(), bridge_native_loop(), builtin_atxfer(), channel_spy(), check_bridge(), common_exec(), conf_play(), conf_run(), dahdi_sendtext(), dahdi_setoption(), dial_exec_full(), dundi_lookup_internal(), eagi_exec(), eivr_comm(), findmeexec(), handle_sendimage(), launch_asyncagi(), lua_check_hangup(), ospfinished_exec(), pbx_builtin_incomplete(), pbx_exec(), read_exec(), readexten_exec(), rpt(), and run_ras().
00463 { 00464 if (chan->_softhangup) /* yes if soft hangup flag set */ 00465 return 1; 00466 if (ast_tvzero(chan->whentohangup)) /* no if no hangup scheduled */ 00467 return 0; 00468 if (ast_tvdiff_ms(chan->whentohangup, ast_tvnow()) > 0) /* no if hangup time has not come yet. */ 00469 return 0; 00470 chan->_softhangup |= AST_SOFTHANGUP_TIMEOUT; /* record event */ 00471 return 1; 00472 }
static int ast_check_hangup_locked | ( | struct ast_channel * | chan | ) | [static] |
Definition at line 474 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_check_hangup(), and chanlist::chan.
Referenced by ast_channel_bridge().
00475 { 00476 int res; 00477 ast_channel_lock(chan); 00478 res = ast_check_hangup(chan); 00479 ast_channel_unlock(chan); 00480 return res; 00481 }
void ast_deactivate_generator | ( | struct ast_channel * | chan | ) |
Deactivate an active generator
Definition at line 1935 of file channel.c.
References ast_channel_lock, ast_channel_set_fd(), ast_channel_unlock, ast_clear_flag, AST_FLAG_WRITE_INT, AST_GENERATOR_FD, ast_settimeout(), chanlist::chan, ast_channel::generator, ast_channel::generatordata, and ast_generator::release.
Referenced by __ast_read(), app_exec(), ast_channel_stop_silence_generator(), ast_openstream_full(), ast_playtones_stop(), ast_quiet_chan(), ast_read_generator_actions(), ast_tonepair_stop(), ast_write(), cb_events(), channel_spy(), dial_exec_full(), generator_force(), local_ast_moh_stop(), old_milliwatt_exec(), transmit_audio(), and wait_for_answer().
01936 { 01937 ast_channel_lock(chan); 01938 if (chan->generatordata) { 01939 if (chan->generator && chan->generator->release) 01940 chan->generator->release(chan, chan->generatordata); 01941 chan->generatordata = NULL; 01942 chan->generator = NULL; 01943 ast_channel_set_fd(chan, AST_GENERATOR_FD, -1); 01944 ast_clear_flag(chan, AST_FLAG_WRITE_INT); 01945 ast_settimeout(chan, 0, NULL, NULL); 01946 } 01947 ast_channel_unlock(chan); 01948 }
int ast_do_masquerade | ( | struct ast_channel * | original | ) |
Start masquerading a channel XXX This is a seriously whacked out operation. We're essentially putting the guts of the clone channel into the original channel. Start by killing off the original channel's backend. I'm not sure we're going to keep this function, because while the features are nice, the cost is very high in terms of pure nastiness. XXX.
Definition at line 4385 of file channel.c.
References ast_channel::_softhangup, ast_channel::_state, ast_channel::adsicpe, ast_channel::alertpipe, ast_app_group_update(), ast_cause2str(), ast_channel_free(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_set_fd(), ast_channel_unlock, ast_copy_string(), ast_debug, AST_FLAG_BLOCKING, AST_FLAG_EXCEPTION, AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, AST_GENERATOR_FD, ast_indicate(), AST_LIST_APPEND_LIST, AST_LIST_FIRST, AST_LIST_HEAD_NOLOCK, AST_LIST_HEAD_SET_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), AST_MAX_FDS, ast_null_frame, ast_queue_frame(), ast_set_flag, ast_set_read_format(), ast_set_write_format(), AST_SOFTHANGUP_DEV, ast_state2str(), ast_string_field_set, ast_test_flag, AST_TIMING_FD, ast_channel::blocker, ast_channel::cdr, ast_datastore_info::chan_fixup, ast_channel::cid, clone_variables(), ast_datastore::data, ast_channel::datastores, ast_datastore::entry, errno, EVENT_FLAG_CALL, ast_channel::fdno, ast_channel::fds, ast_channel_tech::fixup, free_translation(), ast_channel_tech::hangup, ast_datastore::info, language, ast_channel::language, ast_channel::lock_dont_use, LOG_WARNING, manager_event, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, musicclass, ast_channel::name, name, ast_channel::nativeformats, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::readq, report_new_callerid(), ast_channel::tech, ast_channel::tech_pvt, ast_channel::timingfd, ast_channel_tech::type, ast_channel::uniqueid, ast_channel::visible_indication, and ast_channel::writeformat.
Referenced by __ast_read(), ast_async_goto(), ast_hangup(), ast_waitfor_nandfds(), ast_write(), do_bridge_masquerade(), handle_invite_replaces(), iax_park(), sip_park(), and sip_park_thread().
04386 { 04387 int x,i; 04388 int res=0; 04389 int origstate; 04390 struct ast_frame *current; 04391 const struct ast_channel_tech *t; 04392 void *t_pvt; 04393 struct ast_callerid tmpcid; 04394 struct ast_channel *clonechan = original->masq; 04395 struct ast_cdr *cdr; 04396 int rformat = original->readformat; 04397 int wformat = original->writeformat; 04398 char newn[AST_CHANNEL_NAME]; 04399 char orig[AST_CHANNEL_NAME]; 04400 char masqn[AST_CHANNEL_NAME]; 04401 char zombn[AST_CHANNEL_NAME]; 04402 04403 ast_debug(4, "Actually Masquerading %s(%d) into the structure of %s(%d)\n", 04404 clonechan->name, clonechan->_state, original->name, original->_state); 04405 04406 manager_event(EVENT_FLAG_CALL, "Masquerade", "Clone: %s\r\nCloneState: %s\r\nOriginal: %s\r\nOriginalState: %s\r\n", 04407 clonechan->name, ast_state2str(clonechan->_state), original->name, ast_state2str(original->_state)); 04408 04409 /* XXX This operation is a bit odd. We're essentially putting the guts of 04410 * the clone channel into the original channel. Start by killing off the 04411 * original channel's backend. While the features are nice, which is the 04412 * reason we're keeping it, it's still awesomely weird. XXX */ 04413 04414 /* We need the clone's lock, too */ 04415 ast_channel_lock(clonechan); 04416 04417 ast_debug(2, "Got clone lock for masquerade on '%s' at %p\n", clonechan->name, &clonechan->lock_dont_use); 04418 04419 /* Having remembered the original read/write formats, we turn off any translation on either 04420 one */ 04421 free_translation(clonechan); 04422 free_translation(original); 04423 04424 04425 /* Unlink the masquerade */ 04426 original->masq = NULL; 04427 clonechan->masqr = NULL; 04428 04429 /* Save the original name */ 04430 ast_copy_string(orig, original->name, sizeof(orig)); 04431 /* Save the new name */ 04432 ast_copy_string(newn, clonechan->name, sizeof(newn)); 04433 /* Create the masq name */ 04434 snprintf(masqn, sizeof(masqn), "%s<MASQ>", newn); 04435 04436 /* Copy the name from the clone channel */ 04437 ast_string_field_set(original, name, newn); 04438 04439 /* Mangle the name of the clone channel */ 04440 ast_string_field_set(clonechan, name, masqn); 04441 04442 /* Notify any managers of the change, first the masq then the other */ 04443 manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", newn, masqn, clonechan->uniqueid); 04444 manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", orig, newn, original->uniqueid); 04445 04446 /* Swap the technologies */ 04447 t = original->tech; 04448 original->tech = clonechan->tech; 04449 clonechan->tech = t; 04450 04451 /* Swap the cdrs */ 04452 cdr = original->cdr; 04453 original->cdr = clonechan->cdr; 04454 clonechan->cdr = cdr; 04455 04456 t_pvt = original->tech_pvt; 04457 original->tech_pvt = clonechan->tech_pvt; 04458 clonechan->tech_pvt = t_pvt; 04459 04460 /* Swap the alertpipes */ 04461 for (i = 0; i < 2; i++) { 04462 x = original->alertpipe[i]; 04463 original->alertpipe[i] = clonechan->alertpipe[i]; 04464 clonechan->alertpipe[i] = x; 04465 } 04466 04467 /* 04468 * Swap the readq's. The end result should be this: 04469 * 04470 * 1) All frames should be on the new (original) channel. 04471 * 2) Any frames that were already on the new channel before this 04472 * masquerade need to be at the end of the readq, after all of the 04473 * frames on the old (clone) channel. 04474 * 3) The alertpipe needs to get poked for every frame that was already 04475 * on the new channel, since we are now using the alert pipe from the 04476 * old (clone) channel. 04477 */ 04478 { 04479 AST_LIST_HEAD_NOLOCK(, ast_frame) tmp_readq; 04480 AST_LIST_HEAD_SET_NOLOCK(&tmp_readq, NULL); 04481 04482 AST_LIST_APPEND_LIST(&tmp_readq, &original->readq, frame_list); 04483 AST_LIST_APPEND_LIST(&original->readq, &clonechan->readq, frame_list); 04484 04485 while ((current = AST_LIST_REMOVE_HEAD(&tmp_readq, frame_list))) { 04486 AST_LIST_INSERT_TAIL(&original->readq, current, frame_list); 04487 if (original->alertpipe[1] > -1) { 04488 int poke = 0; 04489 04490 if (write(original->alertpipe[1], &poke, sizeof(poke)) < 0) { 04491 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); 04492 } 04493 } 04494 } 04495 } 04496 04497 /* Swap the raw formats */ 04498 x = original->rawreadformat; 04499 original->rawreadformat = clonechan->rawreadformat; 04500 clonechan->rawreadformat = x; 04501 x = original->rawwriteformat; 04502 original->rawwriteformat = clonechan->rawwriteformat; 04503 clonechan->rawwriteformat = x; 04504 04505 clonechan->_softhangup = AST_SOFTHANGUP_DEV; 04506 04507 /* And of course, so does our current state. Note we need not 04508 call ast_setstate since the event manager doesn't really consider 04509 these separate. We do this early so that the clone has the proper 04510 state of the original channel. */ 04511 origstate = original->_state; 04512 original->_state = clonechan->_state; 04513 clonechan->_state = origstate; 04514 04515 if (clonechan->tech->fixup){ 04516 res = clonechan->tech->fixup(original, clonechan); 04517 if (res) 04518 ast_log(LOG_WARNING, "Fixup failed on channel %s, strange things may happen.\n", clonechan->name); 04519 } 04520 04521 /* Start by disconnecting the original's physical side */ 04522 if (clonechan->tech->hangup) 04523 res = clonechan->tech->hangup(clonechan); 04524 if (res) { 04525 ast_log(LOG_WARNING, "Hangup failed! Strange things may happen!\n"); 04526 ast_channel_unlock(clonechan); 04527 return -1; 04528 } 04529 04530 snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig); 04531 /* Mangle the name of the clone channel */ 04532 ast_string_field_set(clonechan, name, zombn); 04533 manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", masqn, zombn, clonechan->uniqueid); 04534 04535 /* Update the type. */ 04536 t_pvt = original->monitor; 04537 original->monitor = clonechan->monitor; 04538 clonechan->monitor = t_pvt; 04539 04540 /* Keep the same language. */ 04541 ast_string_field_set(original, language, clonechan->language); 04542 /* Copy the FD's other than the generator fd */ 04543 for (x = 0; x < AST_MAX_FDS; x++) { 04544 if (x != AST_GENERATOR_FD) 04545 ast_channel_set_fd(original, x, clonechan->fds[x]); 04546 } 04547 04548 ast_app_group_update(clonechan, original); 04549 04550 /* Move data stores over */ 04551 if (AST_LIST_FIRST(&clonechan->datastores)) { 04552 struct ast_datastore *ds; 04553 /* We use a safe traversal here because some fixup routines actually 04554 * remove the datastore from the list and free them. 04555 */ 04556 AST_LIST_TRAVERSE_SAFE_BEGIN(&clonechan->datastores, ds, entry) { 04557 if (ds->info->chan_fixup) 04558 ds->info->chan_fixup(ds->data, clonechan, original); 04559 } 04560 AST_LIST_TRAVERSE_SAFE_END; 04561 AST_LIST_APPEND_LIST(&original->datastores, &clonechan->datastores, entry); 04562 } 04563 04564 clone_variables(original, clonechan); 04565 /* Presense of ADSI capable CPE follows clone */ 04566 original->adsicpe = clonechan->adsicpe; 04567 /* Bridge remains the same */ 04568 /* CDR fields remain the same */ 04569 /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */ 04570 /* Application and data remain the same */ 04571 /* Clone exception becomes real one, as with fdno */ 04572 ast_set_flag(original, ast_test_flag(clonechan, AST_FLAG_OUTGOING | AST_FLAG_EXCEPTION)); 04573 original->fdno = clonechan->fdno; 04574 /* Schedule context remains the same */ 04575 /* Stream stuff stays the same */ 04576 /* Keep the original state. The fixup code will need to work with it most likely */ 04577 04578 /* Just swap the whole structures, nevermind the allocations, they'll work themselves 04579 out. */ 04580 tmpcid = original->cid; 04581 original->cid = clonechan->cid; 04582 clonechan->cid = tmpcid; 04583 report_new_callerid(original); 04584 04585 /* Restore original timing file descriptor */ 04586 ast_channel_set_fd(original, AST_TIMING_FD, original->timingfd); 04587 04588 /* Our native formats are different now */ 04589 original->nativeformats = clonechan->nativeformats; 04590 04591 /* Context, extension, priority, app data, jump table, remain the same */ 04592 /* pvt switches. pbx stays the same, as does next */ 04593 04594 /* Set the write format */ 04595 ast_set_write_format(original, wformat); 04596 04597 /* Set the read format */ 04598 ast_set_read_format(original, rformat); 04599 04600 /* Copy the music class */ 04601 ast_string_field_set(original, musicclass, clonechan->musicclass); 04602 04603 ast_debug(1, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat); 04604 04605 /* Okay. Last thing is to let the channel driver know about all this mess, so he 04606 can fix up everything as best as possible */ 04607 if (original->tech->fixup) { 04608 res = original->tech->fixup(clonechan, original); 04609 if (res) { 04610 ast_log(LOG_WARNING, "Channel for type '%s' could not fixup channel %s\n", 04611 original->tech->type, original->name); 04612 ast_channel_unlock(clonechan); 04613 return -1; 04614 } 04615 } else 04616 ast_log(LOG_WARNING, "Channel type '%s' does not have a fixup routine (for %s)! Bad things may happen.\n", 04617 original->tech->type, original->name); 04618 04619 /* 04620 * If an indication is currently playing, maintain it on the channel 04621 * that is taking the place of original 04622 * 04623 * This is needed because the masquerade is swapping out in the internals 04624 * of this channel, and the new channel private data needs to be made 04625 * aware of the current visible indication (RINGING, CONGESTION, etc.) 04626 */ 04627 if (original->visible_indication) { 04628 ast_indicate(original, original->visible_indication); 04629 } 04630 04631 /* Now, at this point, the "clone" channel is totally F'd up. We mark it as 04632 a zombie so nothing tries to touch it. If it's already been marked as a 04633 zombie, then free it now (since it already is considered invalid). */ 04634 if (ast_test_flag(clonechan, AST_FLAG_ZOMBIE)) { 04635 ast_debug(1, "Destroying channel clone '%s'\n", clonechan->name); 04636 ast_channel_unlock(clonechan); 04637 manager_event(EVENT_FLAG_CALL, "Hangup", 04638 "Channel: %s\r\n" 04639 "Uniqueid: %s\r\n" 04640 "Cause: %d\r\n" 04641 "Cause-txt: %s\r\n", 04642 clonechan->name, 04643 clonechan->uniqueid, 04644 clonechan->hangupcause, 04645 ast_cause2str(clonechan->hangupcause) 04646 ); 04647 ast_channel_free(clonechan); 04648 } else { 04649 ast_debug(1, "Released clone lock on '%s'\n", clonechan->name); 04650 ast_set_flag(clonechan, AST_FLAG_ZOMBIE); 04651 ast_queue_frame(clonechan, &ast_null_frame); 04652 ast_channel_unlock(clonechan); 04653 } 04654 04655 /* Signal any blocker */ 04656 if (ast_test_flag(original, AST_FLAG_BLOCKING)) 04657 pthread_kill(original->blocker, SIGURG); 04658 ast_debug(1, "Done Masquerading %s (%d)\n", original->name, original->_state); 04659 return 0; 04660 }
static enum ast_bridge_result ast_generic_bridge | ( | struct ast_channel * | c0, | |
struct ast_channel * | c1, | |||
struct ast_bridge_config * | config, | |||
struct ast_frame ** | fo, | |||
struct ast_channel ** | rc, | |||
struct timeval | bridge_end | |||
) | [static] |
Definition at line 4768 of file channel.c.
References AST_BRIDGE_COMPLETE, AST_BRIDGE_DTMF_CHANNEL_0, AST_BRIDGE_DTMF_CHANNEL_1, AST_BRIDGE_RETRY, AST_FEATURE_WARNING_ACTIVE, ast_jb_do_usecheck(), ast_jb_empty_and_reset(), ast_poll_channel_add(), ast_samp2tv(), ast_set_flag, ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), config, f, ast_channel::nativeformats, and ast_channel::tech_pvt.
Referenced by ast_channel_bridge().
04771 { 04772 /* Copy voice back and forth between the two channels. */ 04773 struct ast_channel *cs[3]; 04774 struct ast_frame *f; 04775 enum ast_bridge_result res = AST_BRIDGE_COMPLETE; 04776 int o0nativeformats; 04777 int o1nativeformats; 04778 int watch_c0_dtmf; 04779 int watch_c1_dtmf; 04780 void *pvt0, *pvt1; 04781 /* Indicates whether a frame was queued into a jitterbuffer */ 04782 int frame_put_in_jb = 0; 04783 int jb_in_use; 04784 int to; 04785 04786 cs[0] = c0; 04787 cs[1] = c1; 04788 pvt0 = c0->tech_pvt; 04789 pvt1 = c1->tech_pvt; 04790 o0nativeformats = c0->nativeformats; 04791 o1nativeformats = c1->nativeformats; 04792 watch_c0_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_0; 04793 watch_c1_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_1; 04794 04795 /* Check the need of a jitterbuffer for each channel */ 04796 jb_in_use = ast_jb_do_usecheck(c0, c1); 04797 if (jb_in_use) 04798 ast_jb_empty_and_reset(c0, c1); 04799 04800 ast_poll_channel_add(c0, c1); 04801 04802 if (config->feature_timer > 0 && ast_tvzero(config->nexteventts)) { 04803 /* calculate when the bridge should possibly break 04804 * if a partial feature match timed out */ 04805 config->partialfeature_timer = ast_tvadd(ast_tvnow(), ast_samp2tv(config->feature_timer, 1000)); 04806 } else { 04807 memset(&config->partialfeature_timer, 0, sizeof(config->partialfeature_timer)); 04808 } 04809 04810 for (;;) { 04811 struct ast_channel *who, *other; 04812 04813 if ((c0->tech_pvt != pvt0) || (c1->tech_pvt != pvt1) || 04814 (o0nativeformats != c0->nativeformats) || 04815 (o1nativeformats != c1->nativeformats)) { 04816 /* Check for Masquerade, codec changes, etc */ 04817 res = AST_BRIDGE_RETRY; 04818 break; 04819 } 04820 if (bridge_end.tv_sec) { 04821 to = ast_tvdiff_ms(bridge_end, ast_tvnow()); 04822 if (to <= 0) { 04823 if (config->timelimit) { 04824 res = AST_BRIDGE_RETRY; 04825 /* generic bridge ending to play warning */ 04826 ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE); 04827 } else { 04828 res = AST_BRIDGE_COMPLETE; 04829 } 04830 break; 04831 } 04832 } else { 04833 /* If a feature has been started and the bridge is configured to 04834 * to not break, leave the channel bridge when the feature timer 04835 * time has elapsed so the DTMF will be sent to the other side. 04836 */ 04837 if (!ast_tvzero(config->partialfeature_timer)) { 04838 int diff = ast_tvdiff_ms(config->partialfeature_timer, ast_tvnow()); 04839 if (diff <= 0) { 04840 res = AST_BRIDGE_RETRY; 04841 break; 04842 } 04843 } 04844 to = -1; 04845 } 04846 /* Calculate the appropriate max sleep interval - in general, this is the time, 04847 left to the closest jb delivery moment */ 04848 if (jb_in_use) 04849 to = ast_jb_get_when_to_wakeup(c0, c1, to); 04850 who = ast_waitfor_n(cs, 2, &to); 04851 if (!who) { 04852 /* No frame received within the specified timeout - check if we have to deliver now */ 04853 if (jb_in_use) 04854 ast_jb_get_and_deliver(c0, c1); 04855 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) { 04856 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 04857 c0->_softhangup = 0; 04858 if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 04859 c1->_softhangup = 0; 04860 c0->_bridge = c1; 04861 c1->_bridge = c0; 04862 } 04863 continue; 04864 } 04865 f = ast_read(who); 04866 if (!f) { 04867 *fo = NULL; 04868 *rc = who; 04869 ast_debug(1, "Didn't get a frame from channel: %s\n",who->name); 04870 break; 04871 } 04872 04873 other = (who == c0) ? c1 : c0; /* the 'other' channel */ 04874 /* Try add the frame info the who's bridged channel jitterbuff */ 04875 if (jb_in_use) 04876 frame_put_in_jb = !ast_jb_put(other, f); 04877 04878 if ((f->frametype == AST_FRAME_CONTROL) && !(config->flags & AST_BRIDGE_IGNORE_SIGS)) { 04879 int bridge_exit = 0; 04880 04881 switch (f->subclass) { 04882 case AST_CONTROL_HOLD: 04883 case AST_CONTROL_UNHOLD: 04884 case AST_CONTROL_VIDUPDATE: 04885 case AST_CONTROL_SRCUPDATE: 04886 case AST_CONTROL_SRCCHANGE: 04887 case AST_CONTROL_T38_PARAMETERS: 04888 ast_indicate_data(other, f->subclass, f->data.ptr, f->datalen); 04889 if (jb_in_use) { 04890 ast_jb_empty_and_reset(c0, c1); 04891 } 04892 break; 04893 default: 04894 *fo = f; 04895 *rc = who; 04896 bridge_exit = 1; 04897 ast_debug(1, "Got a FRAME_CONTROL (%d) frame on channel %s\n", f->subclass, who->name); 04898 break; 04899 } 04900 if (bridge_exit) 04901 break; 04902 } 04903 if ((f->frametype == AST_FRAME_VOICE) || 04904 (f->frametype == AST_FRAME_DTMF_BEGIN) || 04905 (f->frametype == AST_FRAME_DTMF) || 04906 (f->frametype == AST_FRAME_VIDEO) || 04907 (f->frametype == AST_FRAME_IMAGE) || 04908 (f->frametype == AST_FRAME_HTML) || 04909 (f->frametype == AST_FRAME_MODEM) || 04910 (f->frametype == AST_FRAME_TEXT)) { 04911 /* monitored dtmf causes exit from bridge */ 04912 int monitored_source = (who == c0) ? watch_c0_dtmf : watch_c1_dtmf; 04913 04914 if (monitored_source && 04915 (f->frametype == AST_FRAME_DTMF_END || 04916 f->frametype == AST_FRAME_DTMF_BEGIN)) { 04917 *fo = f; 04918 *rc = who; 04919 ast_debug(1, "Got DTMF %s on channel (%s)\n", 04920 f->frametype == AST_FRAME_DTMF_END ? "end" : "begin", 04921 who->name); 04922 04923 break; 04924 } 04925 /* Write immediately frames, not passed through jb */ 04926 if (!frame_put_in_jb) 04927 ast_write(other, f); 04928 04929 /* Check if we have to deliver now */ 04930 if (jb_in_use) 04931 ast_jb_get_and_deliver(c0, c1); 04932 } 04933 /* XXX do we want to pass on also frames not matched above ? */ 04934 ast_frfree(f); 04935 04936 #ifndef HAVE_EPOLL 04937 /* Swap who gets priority */ 04938 cs[2] = cs[0]; 04939 cs[0] = cs[1]; 04940 cs[1] = cs[2]; 04941 #endif 04942 } 04943 04944 ast_poll_channel_del(c0, c1); 04945 04946 return res; 04947 }
struct ast_channel* ast_get_channel_by_exten_locked | ( | const char * | exten, | |
const char * | context | |||
) |
Get channel by exten (and optionally context) and lock it.
Definition at line 1298 of file channel.c.
References channel_find_locked().
01299 { 01300 return channel_find_locked(NULL, NULL, 0, context, exten); 01301 }
struct ast_channel* ast_get_channel_by_name_locked | ( | const char * | name | ) |
Get channel by name or uniqueid (locks channel).
Definition at line 1279 of file channel.c.
References channel_find_locked().
Referenced by acf_import(), action_add_agi_cmd(), action_atxfer(), action_getvar(), action_hangup(), action_redirect(), action_sendtext(), action_setvar(), action_status(), action_timeout(), ast_async_goto_by_name(), ast_bridge_call(), ast_park_call_full(), asyncgoto_exec(), change_monitor_action(), do_pause_or_unpause(), get_dahdi_channel_locked(), handle_channelstatus(), handle_cli_agi_add_cmd(), handle_core_set_debug_channel(), handle_getvariablefull(), handle_hangup(), handle_set_chanvar(), handle_show_chanvar(), handle_showchan(), handle_softhangup(), manager_park(), manager_play_dtmf(), pbx_builtin_importvar(), shared_read(), shared_write(), start_monitor_action(), and stop_monitor_action().
01280 { 01281 return channel_find_locked(NULL, name, 0, NULL, NULL); 01282 }
struct ast_channel* ast_get_channel_by_name_prefix_locked | ( | const char * | name, | |
const int | namelen | |||
) |
Get channel by name or uniqueid prefix (locks channel).
Definition at line 1285 of file channel.c.
References channel_find_locked().
Referenced by action_bridge(), ast_parse_device_state(), bridge_exec(), common_exec(), handle_cli_mixmonitor(), shared_read(), and shared_write().
01286 { 01287 return channel_find_locked(NULL, name, namelen, NULL, NULL); 01288 }
struct ast_channel_tech* ast_get_channel_tech | ( | const char * | name | ) |
Get a channel technology structure by name.
name | name of technology to find |
Definition at line 610 of file channel.c.
References AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, chanlist::list, chanlist::tech, and ast_channel_tech::type.
Referenced by __ast_channel_alloc_ap(), and _ast_device_state().
00611 { 00612 struct chanlist *chanls; 00613 const struct ast_channel_tech *ret = NULL; 00614 00615 AST_RWLIST_RDLOCK(&channels); 00616 00617 AST_LIST_TRAVERSE(&backends, chanls, list) { 00618 if (!strcasecmp(name, chanls->tech->type)) { 00619 ret = chanls->tech; 00620 break; 00621 } 00622 } 00623 00624 AST_RWLIST_UNLOCK(&channels); 00625 00626 return ret; 00627 }
ast_group_t ast_get_group | ( | const char * | s | ) |
Definition at line 5481 of file channel.c.
References ast_log(), ast_strdupa, ast_strlen_zero(), LOG_ERROR, LOG_WARNING, and strsep().
Referenced by _parse(), build_device(), build_gateway(), build_peer(), func_channel_write(), and read_agent_config().
05482 { 05483 char *piece; 05484 char *c; 05485 int start=0, finish=0, x; 05486 ast_group_t group = 0; 05487 05488 if (ast_strlen_zero(s)) 05489 return 0; 05490 05491 c = ast_strdupa(s); 05492 05493 while ((piece = strsep(&c, ","))) { 05494 if (sscanf(piece, "%30d-%30d", &start, &finish) == 2) { 05495 /* Range */ 05496 } else if (sscanf(piece, "%30d", &start)) { 05497 /* Just one */ 05498 finish = start; 05499 } else { 05500 ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece); 05501 continue; 05502 } 05503 for (x = start; x <= finish; x++) { 05504 if ((x > 63) || (x < 0)) { 05505 ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x); 05506 } else 05507 group |= ((ast_group_t) 1 << x); 05508 } 05509 } 05510 return group; 05511 }
int ast_hangup | ( | struct ast_channel * | chan | ) |
Hang up a channel.
chan | channel to hang up |
Definition at line 1669 of file channel.c.
References ast_assert, ast_audiohook_detach_list(), ast_autoservice_stop(), ast_cause2str(), ast_cdr_detach(), ast_cdr_end(), AST_CDR_FLAG_BRIDGED, AST_CDR_FLAG_DIALED, AST_CDR_FLAG_POST_DISABLED, AST_CDR_NULL, ast_channel_free(), ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_closestream(), ast_debug, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_IN_CHANNEL_LIST, AST_FLAG_ZOMBIE, ast_log(), AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_set_flag, ast_test_flag, ast_channel::audiohooks, ast_channel::blocker, ast_channel::blockproc, ast_channel::cdr, chanlist::chan, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, ast_cdr::disposition, EVENT_FLAG_CALL, free_translation(), ast_channel::generator, ast_channel::generatordata, ast_channel_tech::hangup, ast_channel::hangupcause, LOG_ERROR, LOG_WARNING, manager_event, ast_channel::masq, ast_channel::masqr, ast_channel::name, ast_generator::release, S_OR, ast_channel::sched, sched_context_destroy(), ast_channel::stream, ast_channel::tech, ast_channel::uniqueid, and ast_channel::vstream.
Referenced by __ast_request_and_dial(), __oh323_new(), action_bridge(), agent_hangup(), agent_read(), alsa_new(), answer_exec_run(), app_exec(), ast_async_goto(), ast_bridge_call_thread(), ast_call_forward(), ast_dial_destroy(), ast_dial_hangup(), ast_feature_request_and_dial(), ast_iax2_new(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_pbx_run_app(), async_wait(), begin_dial_channel(), bridge_exec(), build_conf(), builtin_atxfer(), chanavail_exec(), check_compat(), check_goto_on_transfer(), clear_caller(), conf_run(), connect_link(), console_new(), dahdi_handle_event(), dahdi_new(), dial_exec_full(), do_forward(), do_hang(), do_idle_thread(), findmeexec(), gtalk_new(), handle_call_forward(), handle_callforward_button(), handle_enbloc_call_message(), handle_frame(), handle_frame_ownerless(), handle_hd_hf(), handle_init_event(), handle_invite_replaces(), handle_offhook_message(), handle_request_invite(), handle_soft_key_event_message(), handle_stimulus_message(), handle_timeout_trip(), handle_transfer_button(), HandleCallOutgoing(), hangup_chan(), hangupcalls(), hanguptree(), iax2_request(), iax_park(), iax_park_thread(), jingle_new(), local_hangup(), manage_parkinglot(), masq_park_call(), mgcp_new(), mgcp_ss(), monitor_dial(), mwi_thread(), nbs_new(), oss_new(), park_exec_full(), parkandannounce_exec(), phone_new(), rpt(), rpt_call(), rpt_tele_thread(), sip_new(), sip_park(), sip_park_thread(), skinny_new(), skinny_ss(), ss_thread(), unistim_new(), usbradio_new(), wait_for_answer(), and wait_for_winner().
01670 { 01671 int res = 0; 01672 01673 /* Don't actually hang up a channel that will masquerade as someone else, or 01674 if someone is going to masquerade as us */ 01675 ast_channel_lock(chan); 01676 01677 if (chan->audiohooks) { 01678 ast_audiohook_detach_list(chan->audiohooks); 01679 chan->audiohooks = NULL; 01680 } 01681 01682 ast_autoservice_stop(chan); 01683 01684 if (chan->masq) { 01685 if (ast_do_masquerade(chan)) 01686 ast_log(LOG_WARNING, "Failed to perform masquerade\n"); 01687 } 01688 01689 if (chan->masq) { 01690 ast_log(LOG_WARNING, "%s getting hung up, but someone is trying to masq into us?!?\n", chan->name); 01691 ast_channel_unlock(chan); 01692 return 0; 01693 } 01694 /* If this channel is one which will be masqueraded into something, 01695 mark it as a zombie already, so we know to free it later */ 01696 if (chan->masqr) { 01697 ast_set_flag(chan, AST_FLAG_ZOMBIE); 01698 ast_channel_unlock(chan); 01699 return 0; 01700 } 01701 ast_channel_unlock(chan); 01702 01703 AST_RWLIST_WRLOCK(&channels); 01704 if (!AST_RWLIST_REMOVE(&channels, chan, chan_list)) { 01705 ast_log(LOG_ERROR, "Unable to find channel in list to free. Assuming it has already been done.\n"); 01706 } 01707 ast_clear_flag(chan, AST_FLAG_IN_CHANNEL_LIST); 01708 AST_RWLIST_UNLOCK(&channels); 01709 01710 ast_channel_lock(chan); 01711 free_translation(chan); 01712 /* Close audio stream */ 01713 if (chan->stream) { 01714 ast_closestream(chan->stream); 01715 chan->stream = NULL; 01716 } 01717 /* Close video stream */ 01718 if (chan->vstream) { 01719 ast_closestream(chan->vstream); 01720 chan->vstream = NULL; 01721 } 01722 if (chan->sched) { 01723 sched_context_destroy(chan->sched); 01724 chan->sched = NULL; 01725 } 01726 01727 if (chan->generatordata) /* Clear any tone stuff remaining */ 01728 if (chan->generator && chan->generator->release) 01729 chan->generator->release(chan, chan->generatordata); 01730 chan->generatordata = NULL; 01731 chan->generator = NULL; 01732 if (ast_test_flag(chan, AST_FLAG_BLOCKING)) { 01733 ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd " 01734 "is blocked by thread %ld in procedure %s! Expect a failure\n", 01735 (long)pthread_self(), chan->name, (long)chan->blocker, chan->blockproc); 01736 ast_assert(ast_test_flag(chan, AST_FLAG_BLOCKING) == 0); 01737 } 01738 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE)) { 01739 ast_debug(1, "Hanging up channel '%s'\n", chan->name); 01740 if (chan->tech->hangup) 01741 res = chan->tech->hangup(chan); 01742 } else { 01743 ast_debug(1, "Hanging up zombie '%s'\n", chan->name); 01744 } 01745 01746 ast_channel_unlock(chan); 01747 manager_event(EVENT_FLAG_CALL, "Hangup", 01748 "Channel: %s\r\n" 01749 "Uniqueid: %s\r\n" 01750 "CallerIDNum: %s\r\n" 01751 "CallerIDName: %s\r\n" 01752 "Cause: %d\r\n" 01753 "Cause-txt: %s\r\n", 01754 chan->name, 01755 chan->uniqueid, 01756 S_OR(chan->cid.cid_num, "<unknown>"), 01757 S_OR(chan->cid.cid_name, "<unknown>"), 01758 chan->hangupcause, 01759 ast_cause2str(chan->hangupcause) 01760 ); 01761 01762 if (chan->cdr && !ast_test_flag(chan->cdr, AST_CDR_FLAG_BRIDGED) && 01763 !ast_test_flag(chan->cdr, AST_CDR_FLAG_POST_DISABLED) && 01764 (chan->cdr->disposition != AST_CDR_NULL || ast_test_flag(chan->cdr, AST_CDR_FLAG_DIALED))) { 01765 ast_channel_lock(chan); 01766 01767 ast_cdr_end(chan->cdr); 01768 ast_cdr_detach(chan->cdr); 01769 chan->cdr = NULL; 01770 ast_channel_unlock(chan); 01771 } 01772 01773 ast_channel_free(chan); 01774 01775 return res; 01776 }
int ast_indicate | ( | struct ast_channel * | chan, | |
int | condition | |||
) |
Indicates condition of channel.
chan | channel to change the indication | |
condition | which condition to indicate on the channel |
Definition at line 3090 of file channel.c.
References ast_indicate_data(), and chanlist::chan.
Referenced by __ast_play_and_record(), agent_new(), alsa_call(), answer_trunk_chan(), ast_bridge_call(), ast_channel_bridge(), ast_do_masquerade(), ast_dtmf_stream(), ast_feature_request_and_dial(), ast_park_call_full(), ast_raw_answer(), attempt_transfer(), builtin_atxfer(), builtin_blindtransfer(), cli_console_answer(), conf_run(), console_call(), dial_exec_full(), do_forward(), finishup(), function_remote(), handle_callforward_button(), handle_frame(), handle_recordfile(), manage_parkinglot(), mgcp_ss(), monitor_dial(), oss_call(), park_exec_full(), pbx_builtin_busy(), pbx_builtin_congestion(), pbx_builtin_proceeding(), pbx_builtin_progress(), pbx_builtin_ringing(), pbx_builtin_waitexten(), queue_exec(), rpt(), rpt_exec(), say_periodic_announcement(), say_position(), send_waveform_to_channel(), skinny_ss(), sla_handle_hold_event(), sla_station_exec(), sla_trunk_exec(), and wait_for_answer().
03091 { 03092 return ast_indicate_data(chan, condition, NULL, 0); 03093 }
int ast_indicate_data | ( | struct ast_channel * | chan, | |
int | condition, | |||
const void * | data, | |||
size_t | datalen | |||
) |
Indicates condition of channel, with payload.
chan | channel to change the indication | |
condition | which condition to indicate on the channel | |
data | pointer to payload data | |
datalen | size of payload data |
Definition at line 3131 of file channel.c.
References ast_channel::_state, _XXX_AST_CONTROL_T38, ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_OFFHOOK, AST_CONTROL_OPTION, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_RING, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, AST_CONTROL_WINK, ast_debug, AST_FLAG_ZOMBIE, ast_get_indication_tone(), ast_log(), ast_playtones_start(), ast_playtones_stop(), AST_STATE_UP, ast_test_flag, chanlist::chan, tone_zone_sound::data, ast_channel_tech::indicate, is_visible_indication(), LOG_WARNING, ast_channel::name, ast_channel::tech, ast_channel::visible_indication, and ast_channel::zone.
Referenced by agent_hangup(), ast_bridge_call(), ast_indicate(), ast_park_call_full(), bridge_native_loop(), login_exec(), manage_parkinglot(), pbx_builtin_waitexten(), transmit_audio(), and transmit_t38().
03133 { 03134 /* By using an enum, we'll get compiler warnings for values not handled 03135 * in switch statements. */ 03136 enum ast_control_frame_type condition = _condition; 03137 const struct tone_zone_sound *ts = NULL; 03138 int res = -1; 03139 03140 ast_channel_lock(chan); 03141 03142 /* Don't bother if the channel is about to go away, anyway. */ 03143 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 03144 ast_channel_unlock(chan); 03145 return -1; 03146 } 03147 03148 if (chan->tech->indicate) { 03149 /* See if the channel driver can handle this condition. */ 03150 res = chan->tech->indicate(chan, condition, data, datalen); 03151 } 03152 03153 ast_channel_unlock(chan); 03154 03155 if (!res) { 03156 /* The channel driver successfully handled this indication */ 03157 if (is_visible_indication(condition)) { 03158 chan->visible_indication = condition; 03159 } 03160 return 0; 03161 } 03162 03163 /* The channel driver does not support this indication, let's fake 03164 * it by doing our own tone generation if applicable. */ 03165 03166 /*!\note If we compare the enumeration type, which does not have any 03167 * negative constants, the compiler may optimize this code away. 03168 * Therefore, we must perform an integer comparison here. */ 03169 if (_condition < 0) { 03170 /* Stop any tones that are playing */ 03171 ast_playtones_stop(chan); 03172 return 0; 03173 } 03174 03175 /* Handle conditions that we have tones for. */ 03176 switch (condition) { 03177 case _XXX_AST_CONTROL_T38: 03178 /* deprecated T.38 control frame */ 03179 return -1; 03180 case AST_CONTROL_T38_PARAMETERS: 03181 /* there is no way to provide 'default' behavior for these 03182 * control frames, so we need to return failure, but there 03183 * is also no value in the log message below being emitted 03184 * since failure to handle these frames is not an 'error' 03185 * so just return right now. 03186 */ 03187 return -1; 03188 case AST_CONTROL_RINGING: 03189 ts = ast_get_indication_tone(chan->zone, "ring"); 03190 /* It is common practice for channel drivers to return -1 if trying 03191 * to indicate ringing on a channel which is up. The idea is to let the 03192 * core generate the ringing inband. However, we don't want the 03193 * warning message about not being able to handle the specific indication 03194 * to print nor do we want ast_indicate_data to return an "error" for this 03195 * condition 03196 */ 03197 if (chan->_state == AST_STATE_UP) { 03198 res = 0; 03199 } 03200 break; 03201 case AST_CONTROL_BUSY: 03202 ts = ast_get_indication_tone(chan->zone, "busy"); 03203 break; 03204 case AST_CONTROL_CONGESTION: 03205 ts = ast_get_indication_tone(chan->zone, "congestion"); 03206 break; 03207 case AST_CONTROL_PROGRESS: 03208 case AST_CONTROL_PROCEEDING: 03209 case AST_CONTROL_VIDUPDATE: 03210 case AST_CONTROL_SRCUPDATE: 03211 case AST_CONTROL_SRCCHANGE: 03212 case AST_CONTROL_RADIO_KEY: 03213 case AST_CONTROL_RADIO_UNKEY: 03214 case AST_CONTROL_OPTION: 03215 case AST_CONTROL_WINK: 03216 case AST_CONTROL_FLASH: 03217 case AST_CONTROL_OFFHOOK: 03218 case AST_CONTROL_TAKEOFFHOOK: 03219 case AST_CONTROL_ANSWER: 03220 case AST_CONTROL_HANGUP: 03221 case AST_CONTROL_RING: 03222 case AST_CONTROL_HOLD: 03223 case AST_CONTROL_UNHOLD: 03224 /* Nothing left to do for these. */ 03225 res = 0; 03226 break; 03227 } 03228 03229 if (ts && ts->data[0]) { 03230 /* We have a tone to play, yay. */ 03231 ast_debug(1, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition); 03232 ast_playtones_start(chan, 0, ts->data, 1); 03233 res = 0; 03234 chan->visible_indication = condition; 03235 } 03236 03237 if (res) { 03238 /* not handled */ 03239 ast_log(LOG_WARNING, "Unable to handle indication %d for '%s'\n", condition, chan->name); 03240 } 03241 03242 return res; 03243 }
void ast_install_music_functions | ( | int(*)(struct ast_channel *, const char *, const char *) | start_ptr, | |
void(*)(struct ast_channel *) | stop_ptr, | |||
void(*)(struct ast_channel *) | cleanup_ptr | |||
) |
Definition at line 5517 of file channel.c.
References ast_moh_cleanup_ptr, ast_moh_start_ptr, and ast_moh_stop_ptr.
Referenced by load_module().
05520 { 05521 ast_moh_start_ptr = start_ptr; 05522 ast_moh_stop_ptr = stop_ptr; 05523 ast_moh_cleanup_ptr = cleanup_ptr; 05524 }
int ast_internal_timing_enabled | ( | struct ast_channel * | chan | ) |
Check if the channel can run in internal timing mode.
chan | The channel to check |
Definition at line 3075 of file channel.c.
References ast_opt_internal_timing, chanlist::chan, and ast_channel::timingfd.
Referenced by add_sdp(), and ast_read_generator_actions().
03076 { 03077 return (ast_opt_internal_timing && chan->timingfd > -1); 03078 }
void ast_moh_cleanup | ( | struct ast_channel * | chan | ) |
Definition at line 5551 of file channel.c.
References ast_moh_cleanup_ptr, and chan.
Referenced by ast_channel_free().
05552 { 05553 if (ast_moh_cleanup_ptr) 05554 ast_moh_cleanup_ptr(chan); 05555 }
int ast_moh_start | ( | struct ast_channel * | chan, | |
const char * | mclass, | |||
const char * | interpclass | |||
) |
Turn on music on hold on a given channel.
chan | The channel structure that will get music on hold | |
mclass | The class to use if the musicclass is not currently set on the channel structure. | |
interpclass | The class to use if the musicclass is not currently set on the channel structure or in the mclass argument. |
Zero | on success | |
non-zero | on failure |
Definition at line 5534 of file channel.c.
References ast_moh_start_ptr, ast_verb, and chan.
Referenced by alsa_indicate(), app_exec(), conf_run(), conf_start_moh(), console_indicate(), dahdi_indicate(), dial_exec_full(), feature_exec_app(), gtalk_indicate(), handle_setmusic(), iax2_indicate(), jingle_indicate(), key_call(), local_indicate(), mgcp_indicate(), misdn_indication(), moh_handle_digit(), monitor_dial(), oh323_indicate(), oss_indicate(), phone_indicate(), play_moh_exec(), queue_exec(), retrydial_exec(), say_periodic_announcement(), say_position(), sip_indicate(), skinny_indicate(), start_moh_exec(), TransferCallStep1(), unistim_indicate(), usbradio_indicate(), and wait_moh_exec().
05535 { 05536 if (ast_moh_start_ptr) 05537 return ast_moh_start_ptr(chan, mclass, interpclass); 05538 05539 ast_verb(3, "Music class %s requested but no musiconhold loaded.\n", mclass ? mclass : (interpclass ? interpclass : "default")); 05540 05541 return 0; 05542 }
void ast_moh_stop | ( | struct ast_channel * | chan | ) |
Turn off music on hold on a given channel.
Turn off music on hold on a given channel
Definition at line 5545 of file channel.c.
References ast_moh_stop_ptr, and chan.
Referenced by alsa_indicate(), app_exec(), ast_quiet_chan(), conf_run(), console_indicate(), dahdi_indicate(), dial_exec_full(), do_bridge_masquerade(), feature_exec_app(), gtalk_indicate(), handle_setmusic(), iax2_indicate(), jingle_indicate(), key_call(), key_dial_page(), local_indicate(), mgcp_indicate(), misdn_indication(), moh_handle_digit(), monitor_dial(), oh323_indicate(), oss_indicate(), phone_indicate(), play_moh_exec(), retrydial_exec(), say_periodic_announcement(), say_position(), sip_indicate(), skinny_indicate(), stop_moh_exec(), unistim_hangup(), unistim_indicate(), usbradio_indicate(), and wait_moh_exec().
05546 { 05547 if (ast_moh_stop_ptr) 05548 ast_moh_stop_ptr(chan); 05549 }
void ast_poll_channel_add | ( | struct ast_channel * | chan0, | |
struct ast_channel * | chan1 | |||
) |
Add a channel to an optimized waitfor
Definition at line 1589 of file channel.c.
References AST_MAX_FDS, and ast_channel::fds.
Referenced by ast_feature_request_and_dial(), ast_generic_bridge(), begin_dial_channel(), bridge_native_loop(), bridge_p2p_loop(), and wait_for_answer().
01590 { 01591 #ifdef HAVE_EPOLL 01592 struct epoll_event ev; 01593 int i = 0; 01594 01595 if (chan0->epfd == -1) 01596 return; 01597 01598 /* Iterate through the file descriptors on chan1, adding them to chan0 */ 01599 for (i = 0; i < AST_MAX_FDS; i++) { 01600 if (chan1->fds[i] == -1) 01601 continue; 01602 ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP; 01603 ev.data.ptr = chan1->epfd_data[i]; 01604 epoll_ctl(chan0->epfd, EPOLL_CTL_ADD, chan1->fds[i], &ev); 01605 } 01606 01607 #endif 01608 return; 01609 }
void ast_poll_channel_del | ( | struct ast_channel * | chan0, | |
struct ast_channel * | chan1 | |||
) |
Delete a channel from an optimized waitfor
Definition at line 1612 of file channel.c.
References AST_MAX_FDS, and ast_channel::fds.
Referenced by ast_feature_request_and_dial(), bridge_native_loop(), monitor_dial(), and wait_for_answer().
01613 { 01614 #ifdef HAVE_EPOLL 01615 struct epoll_event ev; 01616 int i = 0; 01617 01618 if (chan0->epfd == -1) 01619 return; 01620 01621 for (i = 0; i < AST_MAX_FDS; i++) { 01622 if (chan1->fds[i] == -1) 01623 continue; 01624 epoll_ctl(chan0->epfd, EPOLL_CTL_DEL, chan1->fds[i], &ev); 01625 } 01626 01627 #endif 01628 return; 01629 }
char* ast_print_group | ( | char * | buf, | |
int | buflen, | |||
ast_group_t | group | |||
) |
print call- and pickup groups into buffer
Definition at line 5563 of file channel.c.
Referenced by _sip_show_peer(), func_channel_read(), function_sippeer(), handle_skinny_show_line(), misdn_cfg_get_config_string(), print_group(), read_config(), and serialize_showchan().
05564 { 05565 unsigned int i; 05566 int first = 1; 05567 char num[3]; 05568 05569 buf[0] = '\0'; 05570 05571 if (!group) /* Return empty string if no group */ 05572 return buf; 05573 05574 for (i = 0; i <= 63; i++) { /* Max group is 63 */ 05575 if (group & ((ast_group_t) 1 << i)) { 05576 if (!first) { 05577 strncat(buf, ", ", buflen - strlen(buf) - 1); 05578 } else { 05579 first = 0; 05580 } 05581 snprintf(num, sizeof(num), "%u", i); 05582 strncat(buf, num, buflen - strlen(buf) - 1); 05583 } 05584 } 05585 return buf; 05586 }
int ast_prod | ( | struct ast_channel * | chan | ) |
Send empty audio to prime a channel driver.
Definition at line 3364 of file channel.c.
References ast_channel::_state, ast_debug, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), AST_STATE_UP, ast_write(), chanlist::chan, ast_frame::data, LOG_WARNING, ast_channel::name, ast_frame::ptr, ast_channel::rawwriteformat, ast_frame::src, and ast_frame::subclass.
Referenced by ast_activate_generator().
03365 { 03366 struct ast_frame a = { AST_FRAME_VOICE }; 03367 char nothing[128]; 03368 03369 /* Send an empty audio frame to get things moving */ 03370 if (chan->_state != AST_STATE_UP) { 03371 ast_debug(1, "Prodding channel '%s'\n", chan->name); 03372 a.subclass = chan->rawwriteformat; 03373 a.data.ptr = nothing + AST_FRIENDLY_OFFSET; 03374 a.src = "ast_prod"; 03375 if (ast_write(chan, &a)) 03376 ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", chan->name); 03377 } 03378 return 0; 03379 }
int ast_queue_control | ( | struct ast_channel * | chan, | |
enum ast_control_frame_type | control | |||
) |
Queue a control frame with payload.
chan | channel to queue frame onto | |
control | type of control frame |
zero | on success | |
non-zero | on failure |
Definition at line 1124 of file channel.c.
References AST_FRAME_CONTROL, ast_queue_frame(), chanlist::chan, and f.
Referenced by __dahdi_exception(), __oh323_update_info(), ast_pickup_call(), attempt_transfer(), auto_congest(), cb_events(), dahdi_handle_event(), dahdi_hangup(), gtalk_is_answered(), gtalk_ringing_ack(), handle_hd_hf(), handle_offhook_message(), handle_request(), handle_request_bye(), handle_request_info(), handle_request_invite(), handle_request_refer(), handle_response(), handle_response_invite(), handle_response_refer(), handle_soft_key_event_message(), handle_stimulus_message(), HandleCallIncoming(), jingle_is_answered(), jingle_ringing_ack(), mgcp_call(), misdn_attempt_transfer(), nbs_call(), phone_call(), pickup_do(), process_sdp(), receive_digit(), remote_hold(), send_cause2ast(), setup_rtp_connection(), skinny_call(), skinny_transfer(), skinny_unhold(), ss_thread(), unistim_call(), and update_state().
01125 { 01126 struct ast_frame f = { AST_FRAME_CONTROL, }; 01127 01128 f.subclass = control; 01129 01130 return ast_queue_frame(chan, &f); 01131 }
int ast_queue_control_data | ( | struct ast_channel * | chan, | |
enum ast_control_frame_type | control, | |||
const void * | data, | |||
size_t | datalen | |||
) |
Queue a control frame with payload.
chan | channel to queue frame onto | |
control | type of control frame | |
data | pointer to payload data to be included in frame | |
datalen | number of bytes of payload data |
0 | success | |
non-zero | failure |
The channel does not need to be locked before calling this function.
Definition at line 1134 of file channel.c.
References AST_FRAME_CONTROL, ast_queue_frame(), chanlist::chan, and f.
Referenced by change_t38_state(), dahdi_handle_event(), dahdi_hangup(), iax2_queue_control_data(), process_sdp(), and skinny_hold().
01136 { 01137 struct ast_frame f = { AST_FRAME_CONTROL, }; 01138 01139 f.subclass = control; 01140 f.data.ptr = (void *) data; 01141 f.datalen = datalen; 01142 01143 return ast_queue_frame(chan, &f); 01144 }
int ast_queue_frame | ( | struct ast_channel * | chan, | |
struct ast_frame * | f | |||
) |
Queue one or more frames to a channel's frame queue.
chan | the channel to queue the frame(s) on | |
f | the frame(s) to queue. Note that the frame(s) will be duplicated by this function. It is the responsibility of the caller to handle freeing the memory associated with the frame(s) being passed if necessary. |
0 | success | |
non-zero | failure |
Definition at line 1081 of file channel.c.
References __ast_queue_frame(), and chanlist::chan.
Referenced by __ast_read(), __oh323_rtp_create(), __oh323_update_info(), action_atxfer(), agent_new(), alsa_call(), ast_channel_masquerade(), ast_channel_setwhentohangup_tv(), ast_do_masquerade(), ast_queue_control(), ast_queue_control_data(), ast_queue_hangup(), ast_queue_hangup_with_cause(), ast_softhangup_nolock(), cb_events(), cli_console_answer(), cli_console_dial(), cli_console_flash(), cli_console_sendtext(), console_answer(), console_call(), console_dial(), console_do_answer(), console_flash(), console_sendtext(), dahdi_queue_frame(), dictate_exec(), do_immediate_setup(), gtalk_handle_dtmf(), handle_keypad_button_message(), handle_request_info(), handle_request_invite(), handle_response_invite(), iax2_queue_frame(), jingle_handle_dtmf(), keypad_digit(), local_queue_frame(), mgcp_queue_frame(), oh323_simulate_dtmf_end(), oss_call(), process_sdp(), queue_dtmf_readq(), receive_digit(), receive_message(), rpt_call(), stream_monitor(), unistim_do_senddigit(), unistim_senddigit_end(), usbradio_read(), and wakeup_sub().
01082 { 01083 return __ast_queue_frame(chan, fin, 0, NULL); 01084 }
int ast_queue_frame_head | ( | struct ast_channel * | chan, | |
struct ast_frame * | f | |||
) |
Queue one or more frames to the head of a channel's frame queue.
chan | the channel to queue the frame(s) on | |
f | the frame(s) to queue. Note that the frame(s) will be duplicated by this function. It is the responsibility of the caller to handle freeing the memory associated with the frame(s) being passed if necessary. |
0 | success | |
non-zero | failure |
Definition at line 1086 of file channel.c.
References __ast_queue_frame(), and chanlist::chan.
Referenced by __ast_answer(), __ast_read(), and ast_autoservice_stop().
01087 { 01088 return __ast_queue_frame(chan, fin, 1, NULL); 01089 }
int ast_queue_hangup | ( | struct ast_channel * | chan | ) |
Queue a hangup frame.
Definition at line 1092 of file channel.c.
References ast_channel::_softhangup, ast_channel_trylock, ast_channel_unlock, AST_CONTROL_HANGUP, AST_FRAME_CONTROL, ast_queue_frame(), AST_SOFTHANGUP_DEV, chanlist::chan, and f.
Referenced by cleanup_connection(), cli_console_hangup(), close_call(), gtalk_hangup_farend(), gtalk_is_answered(), handle_onhook_message(), handle_request_bye(), handle_request_cancel(), handle_soft_key_event_message(), iax2_destroy(), iax2_queue_hangup(), jingle_hangup_farend(), local_hangup(), and mgcp_queue_hangup().
01093 { 01094 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; 01095 /* Yeah, let's not change a lock-critical value without locking */ 01096 if (!ast_channel_trylock(chan)) { 01097 chan->_softhangup |= AST_SOFTHANGUP_DEV; 01098 ast_channel_unlock(chan); 01099 } 01100 return ast_queue_frame(chan, &f); 01101 }
int ast_queue_hangup_with_cause | ( | struct ast_channel * | chan, | |
int | cause | |||
) |
Queue a hangup frame with hangupcause set.
[in] | chan | channel to queue frame onto |
[in] | cause | the hangup cause |
Definition at line 1104 of file channel.c.
References ast_channel::_softhangup, ast_channel_trylock, ast_channel_unlock, AST_CONTROL_HANGUP, AST_FRAME_CONTROL, ast_queue_frame(), AST_SOFTHANGUP_DEV, chanlist::chan, f, and ast_channel::hangupcause.
Referenced by __oh323_update_info(), __sip_autodestruct(), close_call(), close_client(), console_hangup(), dahdi_handle_event(), handle_request_bye(), handle_response(), handle_response_invite(), handle_response_notify(), HandleCallOutgoing(), hangup_chan(), hangup_connection(), misdn_answer(), pri_hangup_all(), retrans_pkt(), and TransferCallStep1().
01105 { 01106 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; 01107 01108 if (cause >= 0) 01109 f.data.uint32 = cause; 01110 01111 /* Yeah, let's not change a lock-critical value without locking */ 01112 if (!ast_channel_trylock(chan)) { 01113 chan->_softhangup |= AST_SOFTHANGUP_DEV; 01114 if (cause < 0) 01115 f.data.uint32 = chan->hangupcause; 01116 01117 ast_channel_unlock(chan); 01118 } 01119 01120 return ast_queue_frame(chan, &f); 01121 }
int ast_raw_answer | ( | struct ast_channel * | chan, | |
int | cdr_answer | |||
) |
Answer a channel.
chan | channel to answer | |
cdr_answer | flag to control whether any associated CDR should be marked as 'answered' |
Unlike ast_answer(), this function will not wait for media flow to begin. The caller should be careful before sending media to the channel before incoming media arrives, as the outgoing media may be lost.
0 | on success | |
non-zero | on failure |
Definition at line 1778 of file channel.c.
References ast_channel::_state, ast_channel_tech::answer, ast_cdr_answer(), ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_FLAG_OUTGOING, AST_FLAG_ZOMBIE, ast_indicate(), ast_setstate(), AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_test_flag, ast_channel::cdr, chanlist::chan, ast_channel::tech, and ast_channel::visible_indication.
Referenced by __ast_answer(), and ast_bridge_call().
01779 { 01780 int res = 0; 01781 01782 ast_channel_lock(chan); 01783 01784 /* You can't answer an outbound call */ 01785 if (ast_test_flag(chan, AST_FLAG_OUTGOING)) { 01786 ast_channel_unlock(chan); 01787 return 0; 01788 } 01789 01790 /* Stop if we're a zombie or need a soft hangup */ 01791 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 01792 ast_channel_unlock(chan); 01793 return -1; 01794 } 01795 01796 ast_channel_unlock(chan); 01797 01798 switch (chan->_state) { 01799 case AST_STATE_RINGING: 01800 case AST_STATE_RING: 01801 ast_channel_lock(chan); 01802 if (chan->tech->answer) { 01803 res = chan->tech->answer(chan); 01804 } 01805 ast_setstate(chan, AST_STATE_UP); 01806 if (cdr_answer) { 01807 ast_cdr_answer(chan->cdr); 01808 } 01809 ast_channel_unlock(chan); 01810 break; 01811 case AST_STATE_UP: 01812 /* Calling ast_cdr_answer when it it has previously been called 01813 * is essentially a no-op, so it is safe. 01814 */ 01815 if (cdr_answer) { 01816 ast_cdr_answer(chan->cdr); 01817 } 01818 break; 01819 default: 01820 break; 01821 } 01822 01823 ast_indicate(chan, -1); 01824 chan->visible_indication = 0; 01825 01826 return res; 01827 }
struct ast_frame* ast_read | ( | struct ast_channel * | chan | ) |
Reads a frame.
chan | channel to read a frame from |
Definition at line 3080 of file channel.c.
References __ast_read(), and chanlist::chan.
Referenced by __adsi_transmit_messages(), __ast_answer(), __ast_play_and_record(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), agent_read(), ast_feature_request_and_dial(), ast_recvtext(), ast_safe_sleep_conditional(), ast_tonepair(), ast_udptl_bridge(), ast_waitfordigit_full(), async_wait(), autoservice_run(), background_detect_exec(), bridge_native_loop(), bridge_p2p_loop(), builtin_atxfer(), channel_spy(), check_goto_on_transfer(), conf_exec(), conf_flush(), conf_run(), dahdi_bridge(), dial_exec_full(), dictate_exec(), disa_exec(), do_idle_thread(), do_waiting(), echo_exec(), eivr_comm(), find_cache(), handle_recordfile(), handle_speechrecognize(), iax_park_thread(), ices_exec(), isAnsweringMachine(), launch_asyncagi(), manage_parkinglot(), masq_park_call(), measurenoise(), misdn_bridge(), monitor_dial(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), recordthread(), rpt(), run_agi(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), speech_background(), ss_thread(), transmit_audio(), transmit_t38(), wait_for_answer(), wait_for_hangup(), wait_for_winner(), waitforring_exec(), and waitstream_core().
03081 { 03082 return __ast_read(chan, 0); 03083 }
static void ast_read_generator_actions | ( | struct ast_channel * | chan, | |
struct ast_frame * | f | |||
) | [static] |
Definition at line 2512 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_deactivate_generator(), ast_debug, ast_format_rate(), AST_FRAME_CNG, ast_internal_timing_enabled(), ast_settimeout(), chanlist::chan, f, ast_generator::generate, ast_channel::generator, generator_force(), ast_channel::generatordata, ast_channel::timingfd, ast_channel::timingfunc, and ast_channel::writeformat.
Referenced by __ast_read().
02513 { 02514 if (chan->generator && chan->generator->generate && chan->generatordata && !ast_internal_timing_enabled(chan)) { 02515 void *tmp = chan->generatordata; 02516 int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples) = chan->generator->generate; 02517 int res; 02518 int samples; 02519 02520 if (chan->timingfunc) { 02521 ast_debug(1, "Generator got voice, switching to phase locked mode\n"); 02522 ast_settimeout(chan, 0, NULL, NULL); 02523 } 02524 02525 chan->generatordata = NULL; /* reset, to let writes go through */ 02526 02527 if (f->subclass != chan->writeformat) { 02528 float factor; 02529 factor = ((float) ast_format_rate(chan->writeformat)) / ((float) ast_format_rate(f->subclass)); 02530 samples = (int) ( ((float) f->samples) * factor ); 02531 } else { 02532 samples = f->samples; 02533 } 02534 02535 /* This unlock is here based on two assumptions that hold true at this point in the 02536 * code. 1) this function is only called from within __ast_read() and 2) all generators 02537 * call ast_write() in their generate callback. 02538 * 02539 * The reason this is added is so that when ast_write is called, the lock that occurs 02540 * there will not recursively lock the channel. Doing this will cause intended deadlock 02541 * avoidance not to work in deeper functions 02542 */ 02543 ast_channel_unlock(chan); 02544 res = generate(chan, tmp, f->datalen, samples); 02545 ast_channel_lock(chan); 02546 chan->generatordata = tmp; 02547 if (res) { 02548 ast_debug(1, "Auto-deactivating generator\n"); 02549 ast_deactivate_generator(chan); 02550 } 02551 02552 } else if (f->frametype == AST_FRAME_CNG) { 02553 if (chan->generator && !chan->timingfunc && (chan->timingfd > -1)) { 02554 ast_debug(1, "Generator got CNG, switching to timed mode\n"); 02555 ast_settimeout(chan, 50, generator_force, chan); 02556 } 02557 } 02558 }
struct ast_frame* ast_read_noaudio | ( | struct ast_channel * | chan | ) |
Reads a frame, returning AST_FRAME_NULL frame if audio.
chan | channel to read a frame from |
Definition at line 3085 of file channel.c.
References __ast_read(), and chanlist::chan.
Referenced by conf_run().
03086 { 03087 return __ast_read(chan, 1); 03088 }
int ast_readstring | ( | struct ast_channel * | c, | |
char * | s, | |||
int | len, | |||
int | timeout, | |||
int | rtimeout, | |||
char * | enders | |||
) |
Reads multiple digits
c | channel to read from | |
s | string to read in to. Must be at least the size of your length | |
len | how many digits to read (maximum) | |
timeout | how long to timeout between digits | |
rtimeout | timeout to wait on the first digit | |
enders | digits to end the string Read in a digit string "s", max length "len", maximum timeout between digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout for the first digit. Returns 0 on normal return, or 1 on a timeout. In the case of a timeout, any digits that were read before the timeout will still be available in s. RETURNS 2 in full version when ctrlfd is available, NOT 1 |
Definition at line 4080 of file channel.c.
References ast_readstring_full().
Referenced by _ast_adsi_begin_download(), _ast_adsi_get_cpeinfo(), _ast_adsi_load_session(), ast_app_getdata(), dialout(), do_directory(), forward_message(), privacy_exec(), vm_authenticate(), vm_newuser(), and vm_options().
04081 { 04082 return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1); 04083 }
int ast_readstring_full | ( | struct ast_channel * | c, | |
char * | s, | |||
int | len, | |||
int | timeout, | |||
int | ftimeout, | |||
char * | enders, | |||
int | audiofd, | |||
int | ctrlfd | |||
) |
Definition at line 4085 of file channel.c.
References ast_check_hangup(), AST_DIGIT_ANY, AST_FLAG_ZOMBIE, AST_GETDATA_COMPLETE, AST_GETDATA_EMPTY_END_TERMINATED, AST_GETDATA_FAILED, AST_GETDATA_INTERRUPTED, AST_GETDATA_TIMEOUT, ast_stopstream(), ast_test_flag, ast_waitfordigit_full(), ast_waitstream_full(), and ast_channel::stream.
Referenced by ast_app_getdata_full(), and ast_readstring().
04086 { 04087 int pos = 0; /* index in the buffer where we accumulate digits */ 04088 int to = ftimeout; 04089 04090 /* Stop if we're a zombie or need a soft hangup */ 04091 if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c)) 04092 return -1; 04093 if (!len) 04094 return -1; 04095 for (;;) { 04096 int d; 04097 if (c->stream) { 04098 d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd); 04099 ast_stopstream(c); 04100 usleep(1000); 04101 if (!d) 04102 d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); 04103 } else { 04104 d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); 04105 } 04106 if (d < 0) 04107 return AST_GETDATA_FAILED; 04108 if (d == 0) { 04109 s[pos] = '\0'; 04110 return AST_GETDATA_TIMEOUT; 04111 } 04112 if (d == 1) { 04113 s[pos] = '\0'; 04114 return AST_GETDATA_INTERRUPTED; 04115 } 04116 if (strchr(enders, d) && (pos == 0)) { 04117 s[pos] = '\0'; 04118 return AST_GETDATA_EMPTY_END_TERMINATED; 04119 } 04120 if (!strchr(enders, d)) { 04121 s[pos++] = d; 04122 } 04123 if (strchr(enders, d) || (pos >= len)) { 04124 s[pos] = '\0'; 04125 return AST_GETDATA_COMPLETE; 04126 } 04127 to = timeout; 04128 } 04129 /* Never reached */ 04130 return 0; 04131 }
int ast_recvchar | ( | struct ast_channel * | chan, | |
int | timeout | |||
) |
Receives a text character from a channel.
chan | channel to act upon | |
timeout | timeout in milliseconds (0 for infinite wait) Read a char of text from a channel Returns 0 on success, -1 on failure |
Definition at line 3245 of file channel.c.
References ast_free, ast_recvtext(), buf, and chanlist::chan.
Referenced by handle_recvchar().
03246 { 03247 int c; 03248 char *buf = ast_recvtext(chan, timeout); 03249 if (buf == NULL) 03250 return -1; /* error or timeout */ 03251 c = *(unsigned char *)buf; 03252 ast_free(buf); 03253 return c; 03254 }
char* ast_recvtext | ( | struct ast_channel * | chan, | |
int | timeout | |||
) |
Receives a text string from a channel Read a string of text from a channel.
chan | channel to act upon | |
timeout | timeout in milliseconds (0 for infinite wait) |
Definition at line 3256 of file channel.c.
References ast_check_hangup(), AST_CONTROL_HANGUP, AST_FRAME_CONTROL, AST_FRAME_TEXT, ast_frfree, ast_read(), ast_strndup, ast_waitfor(), buf, chanlist::chan, and f.
Referenced by ast_recvchar(), and handle_recvtext().
03257 { 03258 int res, done = 0; 03259 char *buf = NULL; 03260 03261 while (!done) { 03262 struct ast_frame *f; 03263 if (ast_check_hangup(chan)) 03264 break; 03265 res = ast_waitfor(chan, timeout); 03266 if (res <= 0) /* timeout or error */ 03267 break; 03268 timeout = res; /* update timeout */ 03269 f = ast_read(chan); 03270 if (f == NULL) 03271 break; /* no frame */ 03272 if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) 03273 done = 1; /* force a break */ 03274 else if (f->frametype == AST_FRAME_TEXT) { /* what we want */ 03275 buf = ast_strndup((char *) f->data.ptr, f->datalen); /* dup and break */ 03276 done = 1; 03277 } 03278 ast_frfree(f); 03279 } 03280 return buf; 03281 }
struct ast_channel* ast_request | ( | const char * | type, | |
int | format, | |||
void * | data, | |||
int * | status | |||
) |
Requests a channel.
type | type of channel to request | |
format | requested channel format (codec) | |
data | data to pass to the channel requester | |
status | status |
NULL | failure | |
non-NULL | channel on success |
Definition at line 3979 of file channel.c.
References AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_NOSUCHDRIVER, AST_CAUSE_NOTDEFINED, AST_FORMAT_AUDIO_MASK, AST_FORMAT_TEXT_MASK, AST_FORMAT_VIDEO_MASK, AST_LIST_TRAVERSE, ast_log(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_translator_best_choice(), capabilities, ast_channel_tech::capabilities, chanlist::chan, chanlist::list, LOG_WARNING, ast_channel_tech::requester, ast_channel::tech, and ast_channel_tech::type.
Referenced by __ast_request_and_dial(), agent_request(), ast_call_forward(), ast_feature_request_and_dial(), attempt_reconnect(), begin_dial_channel(), build_conf(), chanavail_exec(), conf_run(), connect_link(), dial_exec_full(), do_forward(), findmeexec(), ring_entry(), rpt(), rpt_call(), rpt_exec(), and rpt_tele_thread().
03980 { 03981 struct chanlist *chan; 03982 struct ast_channel *c; 03983 int capabilities; 03984 int fmt; 03985 int res; 03986 int foo; 03987 int videoformat = format & AST_FORMAT_VIDEO_MASK; 03988 int textformat = format & AST_FORMAT_TEXT_MASK; 03989 03990 if (!cause) 03991 cause = &foo; 03992 *cause = AST_CAUSE_NOTDEFINED; 03993 03994 if (AST_RWLIST_RDLOCK(&channels)) { 03995 ast_log(LOG_WARNING, "Unable to lock channel list\n"); 03996 return NULL; 03997 } 03998 03999 AST_LIST_TRAVERSE(&backends, chan, list) { 04000 if (strcasecmp(type, chan->tech->type)) 04001 continue; 04002 04003 capabilities = chan->tech->capabilities; 04004 fmt = format & AST_FORMAT_AUDIO_MASK; 04005 if (fmt) { 04006 /* We have audio - is it possible to connect the various calls to each other? 04007 (Avoid this check for calls without audio, like text+video calls) 04008 */ 04009 res = ast_translator_best_choice(&fmt, &capabilities); 04010 if (res < 0) { 04011 ast_log(LOG_WARNING, "No translator path exists for channel type %s (native 0x%x) to 0x%x\n", type, chan->tech->capabilities, format); 04012 *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; 04013 AST_RWLIST_UNLOCK(&channels); 04014 return NULL; 04015 } 04016 } 04017 AST_RWLIST_UNLOCK(&channels); 04018 if (!chan->tech->requester) 04019 return NULL; 04020 04021 if (!(c = chan->tech->requester(type, capabilities | videoformat | textformat, data, cause))) 04022 return NULL; 04023 04024 /* no need to generate a Newchannel event here; it is done in the channel_alloc call */ 04025 return c; 04026 } 04027 04028 ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type); 04029 *cause = AST_CAUSE_NOSUCHDRIVER; 04030 AST_RWLIST_UNLOCK(&channels); 04031 04032 return NULL; 04033 }
struct ast_channel* ast_request_and_dial | ( | const char * | type, | |
int | format, | |||
void * | data, | |||
int | timeout, | |||
int * | reason, | |||
const char * | cid_num, | |||
const char * | cid_name | |||
) |
Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it.
type | type of channel to request | |
format | requested channel format | |
data | data to pass to the channel requester | |
timeout | maximum amount of time to wait for an answer | |
reason | why unsuccessful (if unsuccessful) | |
cid_num | Caller-ID Number | |
cid_name | Caller-ID Name (ascii) |
Definition at line 3974 of file channel.c.
References __ast_request_and_dial().
Referenced by ast_pbx_outgoing_exten().
03975 { 03976 return __ast_request_and_dial(type, format, data, timeout, outstate, cidnum, cidname, NULL); 03977 }
int ast_safe_sleep | ( | struct ast_channel * | chan, | |
int | ms | |||
) |
Wait for a specified amount of time, looking for hangups.
chan | channel to wait for | |
ms | length of time in milliseconds to sleep Waits for a specified amount of time, servicing the channel as required. |
Definition at line 1350 of file channel.c.
References ast_safe_sleep_conditional(), and chanlist::chan.
Referenced by _ast_adsi_transmit_message_full(), alarmreceiver_exec(), ast_dtmf_stream(), ast_senddigit(), builtin_atxfer(), builtin_parkcall(), conf_run(), dictate_exec(), flash_exec(), function_ilink(), handle_callforward_button(), login_exec(), mgcp_ss(), milliwatt_exec(), misdn_check_l2l1(), old_milliwatt_exec(), park_call_exec(), pbx_builtin_wait(), play_moh_exec(), play_tone_pair(), playtone(), privacy_exec(), receive_ademco_contact_id(), rpt_call(), rpt_exec(), rpt_tele_thread(), send_morse(), send_tone_telemetry(), skinny_ss(), ss_thread(), testclient_exec(), testserver_exec(), wait_for_hangup(), wait_interval(), wait_moh_exec(), waituntil_exec(), and zapateller_exec().
01351 { 01352 return ast_safe_sleep_conditional(chan, ms, NULL, NULL); 01353 }
int ast_safe_sleep_conditional | ( | struct ast_channel * | chan, | |
int | ms, | |||
int(*)(void *) | cond, | |||
void * | data | |||
) |
Wait for a specified amount of time, looking for hangups and a condition argument.
chan | channel to wait for | |
ms | length of time in milliseconds to sleep | |
cond | a function pointer for testing continue condition | |
data | argument to be passed to the condition test function |
Definition at line 1311 of file channel.c.
References ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_frfree, ast_opt_transmit_silence, ast_read(), ast_waitfor(), chanlist::chan, f, and ast_channel::generatordata.
Referenced by ast_safe_sleep(), and login_exec().
01312 { 01313 struct ast_frame *f; 01314 struct ast_silence_generator *silgen = NULL; 01315 int res = 0; 01316 01317 /* If no other generator is present, start silencegen while waiting */ 01318 if (ast_opt_transmit_silence && !chan->generatordata) { 01319 silgen = ast_channel_start_silence_generator(chan); 01320 } 01321 01322 while (ms > 0) { 01323 if (cond && ((*cond)(data) == 0)) { 01324 break; 01325 } 01326 ms = ast_waitfor(chan, ms); 01327 if (ms < 0) { 01328 res = -1; 01329 break; 01330 } 01331 if (ms > 0) { 01332 f = ast_read(chan); 01333 if (!f) { 01334 res = -1; 01335 break; 01336 } 01337 ast_frfree(f); 01338 } 01339 } 01340 01341 /* stop silgen if present */ 01342 if (silgen) { 01343 ast_channel_stop_silence_generator(chan, silgen); 01344 } 01345 01346 return res; 01347 }
int ast_say_character_str | ( | struct ast_channel * | chan, | |
const char * | str, | |||
const char * | ints, | |||
const char * | lang | |||
) |
Definition at line 5835 of file channel.c.
References ast_say_character_str_full, and chan.
Referenced by common_exec(), pbx_builtin_saycharacters(), play_mailbox_owner(), rpt_tele_thread(), saycharstr(), and saynode().
05837 { 05838 return ast_say_character_str_full(chan, str, ints, lang, -1, -1); 05839 }
int ast_say_digit_str | ( | struct ast_channel * | chan, | |
const char * | str, | |||
const char * | ints, | |||
const char * | lang | |||
) |
Definition at line 5829 of file channel.c.
References ast_say_digit_str_full, and chan.
Referenced by forward_message(), invent_message(), mgcp_ss(), pbx_builtin_saydigits(), play_message_callerid(), and ss_thread().
05831 { 05832 return ast_say_digit_str_full(chan, str, ints, lang, -1, -1); 05833 }
int ast_say_digits | ( | struct ast_channel * | chan, | |
int | num, | |||
const char * | ints, | |||
const char * | lang | |||
) |
Definition at line 5823 of file channel.c.
References ast_say_digits_full(), and chan.
Referenced by ast_park_call_full(), common_exec(), conf_exec(), conf_run(), parkandannounce_exec(), and rpt_tele_thread().
05825 { 05826 return ast_say_digits_full(chan, num, ints, lang, -1, -1); 05827 }
int ast_say_digits_full | ( | struct ast_channel * | chan, | |
int | num, | |||
const char * | ints, | |||
const char * | lang, | |||
int | audiofd, | |||
int | ctrlfd | |||
) |
Definition at line 5847 of file channel.c.
References ast_say_digit_str_full, and chan.
Referenced by ast_say_digits(), ast_say_enumeration_full_da(), ast_say_enumeration_full_de(), ast_say_number_full_cs(), ast_say_number_full_da(), ast_say_number_full_de(), ast_say_number_full_en(), ast_say_number_full_en_GB(), ast_say_number_full_es(), ast_say_number_full_fr(), ast_say_number_full_he(), ast_say_number_full_hu(), ast_say_number_full_it(), ast_say_number_full_ka(), ast_say_number_full_nl(), ast_say_number_full_no(), ast_say_number_full_pt(), ast_say_number_full_ru(), ast_say_number_full_se(), ast_say_number_full_th(), ast_say_number_full_zh(), and say_init_mode().
05849 { 05850 char buf[256]; 05851 05852 snprintf(buf, sizeof(buf), "%d", num); 05853 05854 return ast_say_digit_str_full(chan, buf, ints, lang, audiofd, ctrlfd); 05855 }
int ast_say_enumeration | ( | struct ast_channel * | chan, | |
int | num, | |||
const char * | ints, | |||
const char * | language, | |||
const char * | options | |||
) |
Definition at line 5817 of file channel.c.
References ast_say_enumeration_full, and chan.
Referenced by ast_say_date_da(), ast_say_date_de(), ast_say_date_with_format_da(), ast_say_date_with_format_de(), ast_say_date_with_format_en(), and ast_say_date_with_format_pl().
05819 { 05820 return ast_say_enumeration_full(chan, num, ints, language, options, -1, -1); 05821 }
int ast_say_number | ( | struct ast_channel * | chan, | |
int | num, | |||
const char * | ints, | |||
const char * | language, | |||
const char * | options | |||
) |
Definition at line 5811 of file channel.c.
References ast_say_number_full, and chan.
Referenced by ast_say_date_da(), ast_say_date_de(), ast_say_date_en(), ast_say_date_fr(), ast_say_date_gr(), ast_say_date_he(), ast_say_date_hu(), ast_say_date_ka(), ast_say_date_nl(), ast_say_date_pt(), ast_say_date_th(), ast_say_date_with_format_da(), ast_say_date_with_format_de(), ast_say_date_with_format_en(), ast_say_date_with_format_es(), ast_say_date_with_format_fr(), ast_say_date_with_format_it(), ast_say_date_with_format_nl(), ast_say_date_with_format_pl(), ast_say_date_with_format_pt(), ast_say_date_with_format_th(), ast_say_datetime_en(), ast_say_datetime_fr(), ast_say_datetime_from_now_en(), ast_say_datetime_from_now_fr(), ast_say_datetime_from_now_he(), ast_say_datetime_from_now_ka(), ast_say_datetime_from_now_pt(), ast_say_datetime_he(), ast_say_datetime_pt(), ast_say_datetime_th(), ast_say_datetime_zh(), ast_say_time_de(), ast_say_time_en(), ast_say_time_fr(), ast_say_time_gr(), ast_say_time_hu(), ast_say_time_ka(), ast_say_time_nl(), ast_say_time_pt(), ast_say_time_pt_BR(), ast_say_time_th(), ast_say_time_zh(), bridge_playfile(), conf_exec(), conf_run(), count_exec(), dictate_exec(), get_folder(), gr_say_number_female(), pbx_builtin_saynumber(), play_message(), play_message_duration(), rpt_tele_thread(), say_and_wait(), say_position(), saynum(), vm_intro_gr(), vm_intro_he(), vm_intro_multilang(), vm_intro_pt(), and vm_intro_pt_BR().
05813 { 05814 return ast_say_number_full(chan, num, ints, language, options, -1, -1); 05815 }
int ast_say_phonetic_str | ( | struct ast_channel * | chan, | |
const char * | str, | |||
const char * | ints, | |||
const char * | lang | |||
) |
Definition at line 5841 of file channel.c.
References ast_say_phonetic_str_full, and chan.
Referenced by pbx_builtin_sayphonetic().
05843 { 05844 return ast_say_phonetic_str_full(chan, str, ints, lang, -1, -1); 05845 }
int ast_senddigit | ( | struct ast_channel * | chan, | |
char | digit, | |||
unsigned int | duration | |||
) |
Send a DTMF digit to a channel Send a DTMF digit to a channel.
chan | channel to act upon | |
digit | the DTMF digit to send, encoded in ASCII | |
duration | the duration of the digit ending in ms |
Definition at line 3354 of file channel.c.
References AST_DEFAULT_EMULATE_DTMF_DURATION, ast_safe_sleep(), ast_senddigit_begin(), ast_senddigit_end(), chanlist::chan, ast_channel_tech::send_digit_begin, and ast_channel::tech.
Referenced by ast_dtmf_stream(), dial_exec_full(), do_dtmf_phone(), manager_play_dtmf(), and rpt_call().
03355 { 03356 if (chan->tech->send_digit_begin) { 03357 ast_senddigit_begin(chan, digit); 03358 ast_safe_sleep(chan, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION)); 03359 } 03360 03361 return ast_senddigit_end(chan, digit, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION)); 03362 }
int ast_senddigit_begin | ( | struct ast_channel * | chan, | |
char | digit | |||
) |
Send a DTMF digit to a channel Send a DTMF digit to a channel.
chan | channel to act upon | |
digit | the DTMF digit to send, encoded in ASCII |
Definition at line 3296 of file channel.c.
References ast_debug, ast_playtones_start(), chanlist::chan, ast_channel::name, ast_channel_tech::send_digit_begin, and ast_channel::tech.
Referenced by agent_digit_begin(), ast_senddigit(), and ast_write().
03297 { 03298 /* Device does not support DTMF tones, lets fake 03299 * it by doing our own generation. */ 03300 static const char* dtmf_tones[] = { 03301 "941+1336", /* 0 */ 03302 "697+1209", /* 1 */ 03303 "697+1336", /* 2 */ 03304 "697+1477", /* 3 */ 03305 "770+1209", /* 4 */ 03306 "770+1336", /* 5 */ 03307 "770+1477", /* 6 */ 03308 "852+1209", /* 7 */ 03309 "852+1336", /* 8 */ 03310 "852+1477", /* 9 */ 03311 "697+1633", /* A */ 03312 "770+1633", /* B */ 03313 "852+1633", /* C */ 03314 "941+1633", /* D */ 03315 "941+1209", /* * */ 03316 "941+1477" /* # */ 03317 }; 03318 03319 if (!chan->tech->send_digit_begin) 03320 return 0; 03321 03322 if (!chan->tech->send_digit_begin(chan, digit)) 03323 return 0; 03324 03325 if (digit >= '0' && digit <='9') 03326 ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0); 03327 else if (digit >= 'A' && digit <= 'D') 03328 ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0); 03329 else if (digit == '*') 03330 ast_playtones_start(chan, 0, dtmf_tones[14], 0); 03331 else if (digit == '#') 03332 ast_playtones_start(chan, 0, dtmf_tones[15], 0); 03333 else { 03334 /* not handled */ 03335 ast_debug(1, "Unable to generate DTMF tone '%c' for '%s'\n", digit, chan->name); 03336 } 03337 03338 return 0; 03339 }
int ast_senddigit_end | ( | struct ast_channel * | chan, | |
char | digit, | |||
unsigned int | duration | |||
) |
Send a DTMF digit to a channel.
Send a DTMF digit to a channel.
chan | channel to act upon | |
digit | the DTMF digit to send, encoded in ASCII | |
duration | the duration of the digit ending in ms |
Definition at line 3341 of file channel.c.
References ast_playtones_stop(), chanlist::chan, ast_channel::generator, ast_channel_tech::send_digit_end, and ast_channel::tech.
Referenced by agent_digit_end(), ast_senddigit(), and ast_write().
03342 { 03343 int res = -1; 03344 03345 if (chan->tech->send_digit_end) 03346 res = chan->tech->send_digit_end(chan, digit, duration); 03347 03348 if (res && chan->generator) 03349 ast_playtones_stop(chan); 03350 03351 return 0; 03352 }
int ast_sendtext | ( | struct ast_channel * | chan, | |
const char * | text | |||
) |
Sends text to a channel.
chan | channel to act upon | |
text | string of text to send on the channel |
0 | on success | |
-1 | on failure |
Definition at line 3283 of file channel.c.
References ast_check_hangup(), ast_clear_flag, AST_FLAG_BLOCKING, AST_FLAG_ZOMBIE, ast_test_flag, chanlist::chan, CHECK_BLOCKING, ast_channel_tech::send_text, and ast_channel::tech.
Referenced by action_sendtext(), agent_sendtext(), handle_sendtext(), send_newkey(), and sendtext_exec().
03284 { 03285 int res = 0; 03286 /* Stop if we're a zombie or need a soft hangup */ 03287 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) 03288 return -1; 03289 CHECK_BLOCKING(chan); 03290 if (chan->tech->send_text) 03291 res = chan->tech->send_text(chan, text); 03292 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03293 return res; 03294 }
void ast_set_callerid | ( | struct ast_channel * | chan, | |
const char * | cid_num, | |||
const char * | cid_name, | |||
const char * | cid_ani | |||
) |
Set caller ID number, name and ANI.
Definition at line 4662 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_free, ast_strdup, chanlist::chan, ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_name, ast_callerid::cid_num, and report_new_callerid().
Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), ast_feature_request_and_dial(), callerid_write(), dahdi_read(), dial_exec_full(), do_forward(), findmeexec(), handle_setcallerid(), mgcp_ss(), read_config(), rpt_exec(), skinny_newcall(), and ss_thread().
04663 { 04664 ast_channel_lock(chan); 04665 04666 if (cid_num) { 04667 if (chan->cid.cid_num) 04668 ast_free(chan->cid.cid_num); 04669 chan->cid.cid_num = ast_strdup(cid_num); 04670 } 04671 if (cid_name) { 04672 if (chan->cid.cid_name) 04673 ast_free(chan->cid.cid_name); 04674 chan->cid.cid_name = ast_strdup(cid_name); 04675 } 04676 if (cid_ani) { 04677 if (chan->cid.cid_ani) 04678 ast_free(chan->cid.cid_ani); 04679 chan->cid.cid_ani = ast_strdup(cid_ani); 04680 } 04681 04682 report_new_callerid(chan); 04683 04684 ast_channel_unlock(chan); 04685 }
int ast_set_read_format | ( | struct ast_channel * | chan, | |
int | format | |||
) |
Sets read format on channel chan Set read format for channel to whichever component of "format" is best.
chan | channel to change | |
format | format to change to |
Definition at line 3712 of file channel.c.
References chanlist::chan, ast_channel::rawreadformat, ast_channel::readformat, ast_channel::readtrans, and set_format().
Referenced by __ast_play_and_record(), __oh323_update_info(), _ast_adsi_transmit_message_full(), agent_call(), alarmreceiver_exec(), ast_channel_make_compatible_helper(), ast_do_masquerade(), attempt_reconnect(), background_detect_exec(), build_conf(), conf_run(), connect_link(), dictate_exec(), do_waiting(), eagi_exec(), echo_exec(), gtalk_rtp_read(), handle_recordfile(), handle_speechrecognize(), ices_exec(), isAnsweringMachine(), jingle_rtp_read(), login_exec(), measurenoise(), mgcp_rtp_read(), oh323_rtp_read(), old_milliwatt_exec(), process_sdp(), rpt(), rpt_exec(), setup_rtp_connection(), sip_rtp_read(), skinny_rtp_read(), socket_process(), speech_background(), transmit_audio(), and unistim_rtp_read().
03713 { 03714 return set_format(chan, fmt, &chan->rawreadformat, &chan->readformat, 03715 &chan->readtrans, 0); 03716 }
void ast_set_variables | ( | struct ast_channel * | chan, | |
struct ast_variable * | vars | |||
) |
adds a list of channel variables to a channel
chan | the channel | |
vars | a linked list of variables |
Definition at line 5588 of file channel.c.
References chan, ast_variable::name, ast_variable::next, pbx_builtin_setvar_helper(), and ast_variable::value.
Referenced by __ast_request_and_dial(), ast_call_forward(), ast_pbx_outgoing_app(), and ast_pbx_outgoing_exten().
05589 { 05590 struct ast_variable *cur; 05591 05592 for (cur = vars; cur; cur = cur->next) 05593 pbx_builtin_setvar_helper(chan, cur->name, cur->value); 05594 }
int ast_set_write_format | ( | struct ast_channel * | chan, | |
int | format | |||
) |
Sets write format on channel chan Set write format for channel to whichever component of "format" is best.
chan | channel to change | |
format | new format for writing |
Definition at line 3718 of file channel.c.
References chanlist::chan, ast_channel::rawwriteformat, set_format(), ast_channel::writeformat, and ast_channel::writetrans.
Referenced by __oh323_update_info(), _ast_adsi_transmit_message_full(), agent_call(), alarmreceiver_exec(), ast_channel_make_compatible_helper(), ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_do_masquerade(), ast_openstream_full(), ast_stopstream(), attempt_reconnect(), build_conf(), chanspy_exec(), conf_run(), connect_link(), echo_exec(), extenspy_exec(), gtalk_rtp_read(), jingle_rtp_read(), linear_alloc(), linear_release(), login_exec(), mgcp_rtp_read(), moh_alloc(), moh_files_release(), moh_release(), mp3_exec(), NBScat_exec(), oh323_rtp_read(), old_milliwatt_exec(), playtones_alloc(), playtones_release(), process_sdp(), rpt(), rpt_exec(), send_waveform_to_channel(), setup_rtp_connection(), sip_rtp_read(), skinny_rtp_read(), socket_process(), tonepair_alloc(), tonepair_release(), transmit_audio(), and unistim_rtp_read().
03719 { 03720 return set_format(chan, fmt, &chan->rawwriteformat, &chan->writeformat, 03721 &chan->writetrans, 1); 03722 }
int ast_setstate | ( | struct ast_channel * | chan, | |
enum ast_channel_state | state | |||
) |
Change the state of a channel.
Definition at line 4687 of file channel.c.
References ast_channel::_state, AST_CHANNEL_NAME, ast_copy_string(), AST_DEVICE_UNKNOWN, ast_devstate_changed_literal(), ast_state2str(), chanlist::chan, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, EVENT_FLAG_CALL, manager_event, name, ast_channel::name, S_OR, and ast_channel::uniqueid.
Referenced by __ast_read(), __dahdi_exception(), __oh323_update_info(), agent_call(), alsa_answer(), ast_raw_answer(), cb_events(), check_availability(), console_answer(), dahdi_answer(), dahdi_call(), dahdi_handle_event(), dahdi_indicate(), dahdi_read(), do_bridge_masquerade(), gtalk_call(), gtalk_newcall(), handle_invite_replaces(), handle_offhook_message(), handle_request_invite(), handle_response_invite(), handle_soft_key_event_message(), handle_stimulus_message(), iax2_call(), jingle_call(), jingle_newcall(), local_queue_frame(), mgcp_answer(), mgcp_call(), mgcp_ss(), misdn_call(), misdn_indication(), nbs_call(), nbs_hangup(), oh323_answer(), oss_answer(), pbx_builtin_busy(), pbx_builtin_congestion(), phone_answer(), phone_call(), phone_exception(), phone_hangup(), phone_write(), release_chan(), release_chan_early(), sip_answer(), skinny_answer(), skinny_call(), skinny_newcall(), ss_thread(), unistim_answer(), unistim_call(), unistim_new(), unistim_ss(), update_state(), usbradio_answer(), and usbradio_call().
04688 { 04689 int oldstate = chan->_state; 04690 char name[AST_CHANNEL_NAME], *dashptr; 04691 04692 if (oldstate == state) 04693 return 0; 04694 04695 ast_copy_string(name, chan->name, sizeof(name)); 04696 if ((dashptr = strrchr(name, '-'))) { 04697 *dashptr = '\0'; 04698 } 04699 04700 chan->_state = state; 04701 04702 /* We have to pass AST_DEVICE_UNKNOWN here because it is entirely possible that the channel driver 04703 * for this channel is using the callback method for device state. If we pass in an actual state here 04704 * we override what they are saying the state is and things go amuck. */ 04705 ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, name); 04706 04707 /* setstate used to conditionally report Newchannel; this is no more */ 04708 manager_event(EVENT_FLAG_CALL, 04709 "Newstate", 04710 "Channel: %s\r\n" 04711 "ChannelState: %d\r\n" 04712 "ChannelStateDesc: %s\r\n" 04713 "CallerIDNum: %s\r\n" 04714 "CallerIDName: %s\r\n" 04715 "Uniqueid: %s\r\n", 04716 chan->name, chan->_state, ast_state2str(chan->_state), 04717 S_OR(chan->cid.cid_num, ""), 04718 S_OR(chan->cid.cid_name, ""), 04719 chan->uniqueid); 04720 04721 return 0; 04722 }
int ast_settimeout | ( | struct ast_channel * | c, | |
unsigned int | rate, | |||
int(*)(const void *data) | func, | |||
void * | data | |||
) |
Enable or disable timer ticks for a channel.
rate | number of timer ticks per second |
Call this function with a rate of 0 to turn off the timer ticks
Definition at line 2386 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_debug, ast_timer_get_max_rate(), ast_timer_set_rate(), ast_channel::timer, ast_channel::timingdata, ast_channel::timingfd, and ast_channel::timingfunc.
Referenced by ast_activate_generator(), ast_closestream(), ast_deactivate_generator(), ast_read_generator_actions(), ast_readaudio_callback(), and filestream_destructor().
02387 { 02388 int res; 02389 unsigned int real_rate = rate, max_rate; 02390 02391 ast_channel_lock(c); 02392 02393 if (c->timingfd == -1) { 02394 ast_channel_unlock(c); 02395 return -1; 02396 } 02397 02398 if (!func) { 02399 rate = 0; 02400 data = NULL; 02401 } 02402 02403 if (rate && rate > (max_rate = ast_timer_get_max_rate(c->timer))) { 02404 real_rate = max_rate; 02405 } 02406 02407 ast_debug(1, "Scheduling timer at (%u requested / %u actual) timer ticks per second\n", rate, real_rate); 02408 02409 res = ast_timer_set_rate(c->timer, real_rate); 02410 02411 c->timingfunc = func; 02412 c->timingdata = data; 02413 02414 ast_channel_unlock(c); 02415 02416 return res; 02417 }
int ast_shutting_down | ( | void | ) |
Returns non-zero if Asterisk is being shut down.
Returns non-zero if Asterisk is being shut down
Definition at line 516 of file channel.c.
Referenced by handle_request_options().
00517 { 00518 return shutting_down; 00519 }
int ast_softhangup | ( | struct ast_channel * | chan, | |
int | reason | |||
) |
Softly hangup up a channel.
chan | channel to be soft-hung-up | |
reason | an AST_SOFTHANGUP_* reason code |
Definition at line 1645 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_softhangup_nolock(), and chanlist::chan.
Referenced by __ast_module_user_hangup_all(), __unload_module(), action_hangup(), agent_hangup(), agent_logoff(), agent_read(), ast_begin_shutdown(), ast_dial_join(), birdbath(), conf_free(), connect_link(), dahdi_handle_event(), flush_telem(), function_ilink(), handle_hangup(), handle_link_data(), handle_softhangup(), login_exec(), manager_park(), read_agent_config(), rpt(), rpt_call(), rpt_do_restart(), rpt_exec(), sla_handle_hold_event(), softhangup_exec(), start_spying(), startmon(), and unload_module().
01646 { 01647 int res; 01648 01649 ast_channel_lock(chan); 01650 res = ast_softhangup_nolock(chan, cause); 01651 ast_channel_unlock(chan); 01652 01653 return res; 01654 }
int ast_softhangup_nolock | ( | struct ast_channel * | chan, | |
int | reason | |||
) |
Softly hangup up a channel (no channel lock).
chan | channel to be soft-hung-up | |
reason | an AST_SOFTHANGUP_* reason code |
Definition at line 1632 of file channel.c.
References ast_channel::_softhangup, ast_debug, AST_FLAG_BLOCKING, ast_null_frame, ast_queue_frame(), ast_test_flag, ast_channel::blocker, chanlist::chan, and ast_channel::name.
Referenced by ast_async_goto(), ast_softhangup(), attempt_transfer(), check_rtp_timeout(), dahdi_softhangup_all(), oh323_indicate(), proc_session_timer(), sip_indicate(), and skinny_indicate().
01633 { 01634 ast_debug(1, "Soft-Hanging up channel '%s'\n", chan->name); 01635 /* Inform channel driver that we need to be hung up, if it cares */ 01636 chan->_softhangup |= cause; 01637 ast_queue_frame(chan, &ast_null_frame); 01638 /* Interrupt any poll call or such */ 01639 if (ast_test_flag(chan, AST_FLAG_BLOCKING)) 01640 pthread_kill(chan->blocker, SIGURG); 01641 return 0; 01642 }
const char* ast_state2str | ( | enum ast_channel_state | state | ) |
Gives the string form of a given channel state.
Definition at line 657 of file channel.c.
References AST_STATE_BUSY, AST_STATE_DIALING, AST_STATE_DIALING_OFFHOOK, AST_STATE_DOWN, AST_STATE_OFFHOOK, AST_STATE_PRERING, AST_STATE_RESERVED, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_threadstorage_get(), buf, STATE2STR_BUFSIZE, and state2str_threadbuf.
Referenced by __ast_channel_alloc_ap(), action_coreshowchannels(), agent_hangup(), ast_do_masquerade(), ast_setstate(), attempt_transfer(), func_channel_read(), handle_chanlist(), handle_invite_replaces(), handle_showchan(), local_attended_transfer(), mgcp_new(), serialize_showchan(), and sip_hangup().
00658 { 00659 char *buf; 00660 00661 switch (state) { 00662 case AST_STATE_DOWN: 00663 return "Down"; 00664 case AST_STATE_RESERVED: 00665 return "Rsrvd"; 00666 case AST_STATE_OFFHOOK: 00667 return "OffHook"; 00668 case AST_STATE_DIALING: 00669 return "Dialing"; 00670 case AST_STATE_RING: 00671 return "Ring"; 00672 case AST_STATE_RINGING: 00673 return "Ringing"; 00674 case AST_STATE_UP: 00675 return "Up"; 00676 case AST_STATE_BUSY: 00677 return "Busy"; 00678 case AST_STATE_DIALING_OFFHOOK: 00679 return "Dialing Offhook"; 00680 case AST_STATE_PRERING: 00681 return "Pre-ring"; 00682 default: 00683 if (!(buf = ast_threadstorage_get(&state2str_threadbuf, STATE2STR_BUFSIZE))) 00684 return "Unknown"; 00685 snprintf(buf, STATE2STR_BUFSIZE, "Unknown (%d)", state); 00686 return buf; 00687 } 00688 }
int ast_str2cause | ( | const char * | name | ) |
Convert a symbolic hangup cause to number.
name | string form of the cause Returns the cause code |
Definition at line 643 of file channel.c.
References ARRAY_LEN, ast_cause::cause, and causes.
Referenced by pbx_builtin_hangup().
00644 { 00645 int x; 00646 00647 for (x = 0; x < ARRAY_LEN(causes); x++) 00648 if (!strncasecmp(causes[x].name, name, strlen(causes[x].name))) 00649 return causes[x].cause; 00650 00651 return -1; 00652 }
int ast_tonepair | ( | struct ast_channel * | chan, | |
int | freq1, | |||
int | freq2, | |||
int | duration, | |||
int | vol | |||
) |
Play a tone pair for a given amount of time
Definition at line 5463 of file channel.c.
References ast_frfree, ast_read(), ast_tonepair_start(), ast_waitfor(), chan, f, and ast_channel::generatordata.
Referenced by zapateller_exec().
05464 { 05465 int res; 05466 05467 if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol))) 05468 return res; 05469 05470 /* Give us some wiggle room */ 05471 while (chan->generatordata && ast_waitfor(chan, 100) >= 0) { 05472 struct ast_frame *f = ast_read(chan); 05473 if (f) 05474 ast_frfree(f); 05475 else 05476 return -1; 05477 } 05478 return 0; 05479 }
int ast_tonepair_start | ( | struct ast_channel * | chan, | |
int | freq1, | |||
int | freq2, | |||
int | duration, | |||
int | vol | |||
) |
Start a tone going
Definition at line 5445 of file channel.c.
References ast_activate_generator(), chan, tonepair_def::duration, tonepair_def::freq1, tonepair_def::freq2, tonepair, and tonepair_def::vol.
Referenced by ast_tonepair(), pbx_builtin_waitexten(), play_dialtone(), play_tone_pair(), rpt_tele_thread(), and sendnoise().
05446 { 05447 struct tonepair_def d = { 0, }; 05448 05449 d.freq1 = freq1; 05450 d.freq2 = freq2; 05451 d.duration = duration; 05452 d.vol = (vol < 1) ? 8192 : vol; /* force invalid to 8192 */ 05453 if (ast_activate_generator(chan, &tonepair, &d)) 05454 return -1; 05455 return 0; 05456 }
void ast_tonepair_stop | ( | struct ast_channel * | chan | ) |
Stop a tone from playing
Definition at line 5458 of file channel.c.
References ast_deactivate_generator(), and chan.
Referenced by sendnoise().
05459 { 05460 ast_deactivate_generator(chan); 05461 }
int ast_transfer | ( | struct ast_channel * | chan, | |
char * | dest | |||
) |
Transfer a channel (if supported). Returns -1 on error, 0 if not supported and 1 if supported and requested.
Called by:
Definition at line 4062 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_FLAG_ZOMBIE, ast_test_flag, chanlist::chan, ast_channel::tech, and ast_channel_tech::transfer.
Referenced by transfer_exec().
04063 { 04064 int res = -1; 04065 04066 /* Stop if we're a zombie or need a soft hangup */ 04067 ast_channel_lock(chan); 04068 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) { 04069 if (chan->tech->transfer) { 04070 res = chan->tech->transfer(chan, dest); 04071 if (!res) 04072 res = 1; 04073 } else 04074 res = 0; 04075 } 04076 ast_channel_unlock(chan); 04077 return res; 04078 }
char* ast_transfercapability2str | ( | int | transfercapability | ) | const |
Gives the string form of a given transfer capability.
transfercapability | transfercapabilty to get the name of Give a name to a transfercapbility See above Returns the text form of the binary transfer capability |
Definition at line 691 of file channel.c.
References AST_TRANS_CAP_3_1K_AUDIO, AST_TRANS_CAP_DIGITAL, AST_TRANS_CAP_DIGITAL_W_TONES, AST_TRANS_CAP_RESTRICTED_DIGITAL, AST_TRANS_CAP_SPEECH, and AST_TRANS_CAP_VIDEO.
Referenced by cb_events(), dahdi_call(), dahdi_new(), misdn_call(), and oh323_call().
00692 { 00693 switch (transfercapability) { 00694 case AST_TRANS_CAP_SPEECH: 00695 return "SPEECH"; 00696 case AST_TRANS_CAP_DIGITAL: 00697 return "DIGITAL"; 00698 case AST_TRANS_CAP_RESTRICTED_DIGITAL: 00699 return "RESTRICTED_DIGITAL"; 00700 case AST_TRANS_CAP_3_1K_AUDIO: 00701 return "3K1AUDIO"; 00702 case AST_TRANS_CAP_DIGITAL_W_TONES: 00703 return "DIGITAL_W_TONES"; 00704 case AST_TRANS_CAP_VIDEO: 00705 return "VIDEO"; 00706 default: 00707 return "UNKNOWN"; 00708 } 00709 }
void ast_uninstall_music_functions | ( | void | ) |
Definition at line 5526 of file channel.c.
References ast_moh_cleanup_ptr, ast_moh_start_ptr, and ast_moh_stop_ptr.
Referenced by unload_module().
05527 { 05528 ast_moh_start_ptr = NULL; 05529 ast_moh_stop_ptr = NULL; 05530 ast_moh_cleanup_ptr = NULL; 05531 }
int ast_waitfor | ( | struct ast_channel * | chan, | |
int | ms | |||
) |
Wait for input on a channel.
chan | channel to wait on | |
ms | length of time to wait on the channel Wait for input on a channel for a given # of milliseconds (<0 for indefinite). |
Definition at line 2370 of file channel.c.
References ast_waitfor_nandfds().
Referenced by __adsi_transmit_messages(), __ast_answer(), __ast_play_and_record(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), ast_dtmf_stream(), ast_recvtext(), ast_safe_sleep_conditional(), ast_tonepair(), async_wait(), background_detect_exec(), channel_spy(), conf_exec(), conf_flush(), dictate_exec(), disa_exec(), do_idle_thread(), do_waiting(), echo_exec(), handle_recordfile(), handle_speechrecognize(), ices_exec(), isAnsweringMachine(), launch_asyncagi(), measurenoise(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), recordthread(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), speech_background(), ss_thread(), transmit_audio(), transmit_t38(), wait_for_hangup(), waitforring_exec(), and waitstream_core().
02371 { 02372 int oldms = ms; /* -1 if no timeout */ 02373 02374 ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms); 02375 if ((ms < 0) && (oldms < 0)) 02376 ms = 0; 02377 return ms; 02378 }
struct ast_channel* ast_waitfor_n | ( | struct ast_channel ** | chan, | |
int | n, | |||
int * | ms | |||
) |
Waits for input on a group of channels Wait for input on an array of channels for a given # of milliseconds.
chan | an array of pointers to channels | |
n | number of channels that are to be waited upon | |
ms | time "ms" is modified in-place, if applicable |
Definition at line 2365 of file channel.c.
References ast_waitfor_nandfds().
Referenced by ast_feature_request_and_dial(), ast_udptl_bridge(), autoservice_run(), bridge_native_loop(), dahdi_bridge(), dial_exec_full(), misdn_bridge(), monitor_dial(), rpt(), wait_for_answer(), and wait_for_winner().
02366 { 02367 return ast_waitfor_nandfds(c, n, NULL, 0, NULL, NULL, ms); 02368 }
int ast_waitfor_n_fd | ( | int * | fds, | |
int | n, | |||
int * | ms, | |||
int * | exception | |||
) |
Waits for input on an fd This version works on fd's only. Be careful with it.
Definition at line 2005 of file channel.c.
References ast_waitfor_nandfds().
Referenced by dundi_lookup_internal(), and dundi_precache_internal().
02006 { 02007 int winner = -1; 02008 ast_waitfor_nandfds(NULL, 0, fds, n, exception, &winner, ms); 02009 return winner; 02010 }
struct ast_channel* ast_waitfor_nandfds | ( | struct ast_channel ** | chan, | |
int | n, | |||
int * | fds, | |||
int | nfds, | |||
int * | exception, | |||
int * | outfd, | |||
int * | ms | |||
) |
Waits for activity on a group of channels.
chan | an array of pointers to channels | |
n | number of channels that are to be waited upon | |
fds | an array of fds to wait upon | |
nfds | the number of fds to wait upon | |
exception | exception flag | |
outfd | fd that had activity on it | |
ms | how long the wait was Big momma function here. Wait for activity on any of the n channels, or any of the nfds file descriptors. |
Definition at line 2017 of file channel.c.
References ast_channel::_softhangup, ast_add_fd(), ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_EXCEPTION, ast_log(), AST_MAX_FDS, ast_poll, ast_set_flag, AST_SOFTHANGUP_TIMEOUT, ast_tvcmp(), ast_tvdiff_ms(), ast_tvnow(), ast_tvsub(), ast_tvzero(), chanlist::chan, CHECK_BLOCKING, errno, and LOG_WARNING.
Referenced by ast_waitfor(), ast_waitfor_n(), ast_waitfor_n_fd(), ast_waitfordigit_full(), conf_run(), eivr_comm(), find_cache(), run_agi(), and waitstream_core().
02020 { 02021 struct timeval start = { 0 , 0 }; 02022 struct pollfd *pfds = NULL; 02023 int res; 02024 long rms; 02025 int x, y, max; 02026 int sz; 02027 struct timeval now = { 0, 0 }; 02028 struct timeval whentohangup = { 0, 0 }, diff; 02029 struct ast_channel *winner = NULL; 02030 struct fdmap { 02031 int chan; 02032 int fdno; 02033 } *fdmap = NULL; 02034 02035 if ((sz = n * AST_MAX_FDS + nfds)) { 02036 pfds = alloca(sizeof(*pfds) * sz); 02037 fdmap = alloca(sizeof(*fdmap) * sz); 02038 } 02039 02040 if (outfd) 02041 *outfd = -99999; 02042 if (exception) 02043 *exception = 0; 02044 02045 /* Perform any pending masquerades */ 02046 for (x = 0; x < n; x++) { 02047 ast_channel_lock(c[x]); 02048 if (c[x]->masq && ast_do_masquerade(c[x])) { 02049 ast_log(LOG_WARNING, "Masquerade failed\n"); 02050 *ms = -1; 02051 ast_channel_unlock(c[x]); 02052 return NULL; 02053 } 02054 if (!ast_tvzero(c[x]->whentohangup)) { 02055 if (ast_tvzero(whentohangup)) 02056 now = ast_tvnow(); 02057 diff = ast_tvsub(c[x]->whentohangup, now); 02058 if (diff.tv_sec < 0 || ast_tvzero(diff)) { 02059 /* Should already be hungup */ 02060 c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT; 02061 ast_channel_unlock(c[x]); 02062 return c[x]; 02063 } 02064 if (ast_tvzero(whentohangup) || ast_tvcmp(diff, whentohangup) < 0) 02065 whentohangup = diff; 02066 } 02067 ast_channel_unlock(c[x]); 02068 } 02069 /* Wait full interval */ 02070 rms = *ms; 02071 /* INT_MAX, not LONG_MAX, because it matters on 64-bit */ 02072 if (!ast_tvzero(whentohangup) && whentohangup.tv_sec < INT_MAX / 1000) { 02073 rms = whentohangup.tv_sec * 1000 + whentohangup.tv_usec / 1000; /* timeout in milliseconds */ 02074 if (*ms >= 0 && *ms < rms) { /* original *ms still smaller */ 02075 rms = *ms; 02076 } 02077 } else if (!ast_tvzero(whentohangup) && rms < 0) { 02078 /* Tiny corner case... call would need to last >24 days */ 02079 rms = INT_MAX; 02080 } 02081 /* 02082 * Build the pollfd array, putting the channels' fds first, 02083 * followed by individual fds. Order is important because 02084 * individual fd's must have priority over channel fds. 02085 */ 02086 max = 0; 02087 for (x = 0; x < n; x++) { 02088 for (y = 0; y < AST_MAX_FDS; y++) { 02089 fdmap[max].fdno = y; /* fd y is linked to this pfds */ 02090 fdmap[max].chan = x; /* channel x is linked to this pfds */ 02091 max += ast_add_fd(&pfds[max], c[x]->fds[y]); 02092 } 02093 CHECK_BLOCKING(c[x]); 02094 } 02095 /* Add the individual fds */ 02096 for (x = 0; x < nfds; x++) { 02097 fdmap[max].chan = -1; 02098 max += ast_add_fd(&pfds[max], fds[x]); 02099 } 02100 02101 if (*ms > 0) 02102 start = ast_tvnow(); 02103 02104 if (sizeof(int) == 4) { /* XXX fix timeout > 600000 on linux x86-32 */ 02105 do { 02106 int kbrms = rms; 02107 if (kbrms > 600000) 02108 kbrms = 600000; 02109 res = ast_poll(pfds, max, kbrms); 02110 if (!res) 02111 rms -= kbrms; 02112 } while (!res && (rms > 0)); 02113 } else { 02114 res = ast_poll(pfds, max, rms); 02115 } 02116 for (x = 0; x < n; x++) 02117 ast_clear_flag(c[x], AST_FLAG_BLOCKING); 02118 if (res < 0) { /* Simulate a timeout if we were interrupted */ 02119 if (errno != EINTR) 02120 *ms = -1; 02121 return NULL; 02122 } 02123 if (!ast_tvzero(whentohangup)) { /* if we have a timeout, check who expired */ 02124 now = ast_tvnow(); 02125 for (x = 0; x < n; x++) { 02126 if (!ast_tvzero(c[x]->whentohangup) && ast_tvcmp(c[x]->whentohangup, now) <= 0) { 02127 c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT; 02128 if (winner == NULL) 02129 winner = c[x]; 02130 } 02131 } 02132 } 02133 if (res == 0) { /* no fd ready, reset timeout and done */ 02134 *ms = 0; /* XXX use 0 since we may not have an exact timeout. */ 02135 return winner; 02136 } 02137 /* 02138 * Then check if any channel or fd has a pending event. 02139 * Remember to check channels first and fds last, as they 02140 * must have priority on setting 'winner' 02141 */ 02142 for (x = 0; x < max; x++) { 02143 res = pfds[x].revents; 02144 if (res == 0) 02145 continue; 02146 if (fdmap[x].chan >= 0) { /* this is a channel */ 02147 winner = c[fdmap[x].chan]; /* override previous winners */ 02148 if (res & POLLPRI) 02149 ast_set_flag(winner, AST_FLAG_EXCEPTION); 02150 else 02151 ast_clear_flag(winner, AST_FLAG_EXCEPTION); 02152 winner->fdno = fdmap[x].fdno; 02153 } else { /* this is an fd */ 02154 if (outfd) 02155 *outfd = pfds[x].fd; 02156 if (exception) 02157 *exception = (res & POLLPRI) ? -1 : 0; 02158 winner = NULL; 02159 } 02160 } 02161 if (*ms > 0) { 02162 *ms -= ast_tvdiff_ms(ast_tvnow(), start); 02163 if (*ms < 0) 02164 *ms = 0; 02165 } 02166 return winner; 02167 }
int ast_waitfordigit | ( | struct ast_channel * | c, | |
int | ms | |||
) |
Waits for a digit.
!
c | channel to wait for a digit on | |
ms | how many milliseconds to wait |
Definition at line 2381 of file channel.c.
References ast_waitfordigit_full().
Referenced by _ast_adsi_get_cpeid(), _ast_adsi_get_cpeinfo(), _ast_adsi_print(), _ast_adsi_read_encoded_dtmf(), _ast_adsi_transmit_message_full(), _while_exec(), advanced_options(), ast_app_dtget(), ast_control_streamfile(), ast_record_review(), builtin_atxfer(), collect_digits(), common_exec(), cpeid_exec(), dialout(), directory_exec(), forward_message(), get_folder(), ivr_dispatch(), mgcp_ss(), my_getsigstr(), pbx_builtin_waitexten(), play_record_review(), read_exec(), read_newoption(), readexten_exec(), retrydial_exec(), select_item_menu(), select_item_pause(), select_item_seq(), sendnoise(), ss_thread(), testclient_exec(), testserver_exec(), vm_execmain(), vm_forwardoptions(), vm_instructions_en(), vm_options(), vm_tempgreeting(), wait_a_bit(), and wait_our_turn().
02382 { 02383 return ast_waitfordigit_full(c, ms, -1, -1); 02384 }
int ast_waitfordigit_full | ( | struct ast_channel * | c, | |
int | ms, | |||
int | audiofd, | |||
int | ctrlfd | |||
) |
Wait for a digit Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
c | channel to wait for a digit on | |
ms | how many milliseconds to wait | |
audiofd | audio file descriptor to write to if audio frames are received | |
ctrlfd | control file descriptor to monitor for reading |
Definition at line 2419 of file channel.c.
References ast_check_hangup(), ast_clear_flag, AST_CONTROL_ANSWER, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_FLAG_END_DTMF_ONLY, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_VOICE, ast_frfree, ast_log(), ast_read(), ast_set_flag, ast_test_flag, ast_waitfor_nandfds(), errno, f, and LOG_WARNING.
Referenced by ast_readstring_full(), ast_waitfordigit(), handle_getoption(), and handle_waitfordigit().
02420 { 02421 /* Stop if we're a zombie or need a soft hangup */ 02422 if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c)) 02423 return -1; 02424 02425 /* Only look for the end of DTMF, don't bother with the beginning and don't emulate things */ 02426 ast_set_flag(c, AST_FLAG_END_DTMF_ONLY); 02427 02428 /* Wait for a digit, no more than ms milliseconds total. */ 02429 02430 while (ms) { 02431 struct ast_channel *rchan; 02432 int outfd=-1; 02433 02434 errno = 0; 02435 rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms); 02436 02437 if (!rchan && outfd < 0 && ms) { 02438 if (errno == 0 || errno == EINTR) 02439 continue; 02440 ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno)); 02441 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 02442 return -1; 02443 } else if (outfd > -1) { 02444 /* The FD we were watching has something waiting */ 02445 ast_log(LOG_WARNING, "The FD we were waiting for has something waiting. Waitfordigit returning numeric 1\n"); 02446 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 02447 return 1; 02448 } else if (rchan) { 02449 int res; 02450 struct ast_frame *f = ast_read(c); 02451 if (!f) 02452 return -1; 02453 02454 switch (f->frametype) { 02455 case AST_FRAME_DTMF_BEGIN: 02456 break; 02457 case AST_FRAME_DTMF_END: 02458 res = f->subclass; 02459 ast_frfree(f); 02460 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 02461 return res; 02462 case AST_FRAME_CONTROL: 02463 switch (f->subclass) { 02464 case AST_CONTROL_HANGUP: 02465 ast_frfree(f); 02466 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 02467 return -1; 02468 case AST_CONTROL_RINGING: 02469 case AST_CONTROL_ANSWER: 02470 case AST_CONTROL_SRCUPDATE: 02471 case AST_CONTROL_SRCCHANGE: 02472 /* Unimportant */ 02473 break; 02474 default: 02475 ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass); 02476 break; 02477 } 02478 break; 02479 case AST_FRAME_VOICE: 02480 /* Write audio if appropriate */ 02481 if (audiofd > -1) { 02482 if (write(audiofd, f->data.ptr, f->datalen) < 0) { 02483 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); 02484 } 02485 } 02486 default: 02487 /* Ignore */ 02488 break; 02489 } 02490 ast_frfree(f); 02491 } 02492 } 02493 02494 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 02495 02496 return 0; /* Time is up */ 02497 }
struct ast_channel* ast_walk_channel_by_exten_locked | ( | const struct ast_channel * | chan, | |
const char * | exten, | |||
const char * | context | |||
) |
Get next channel by exten (and optionally context) and lock it.
Definition at line 1304 of file channel.c.
References chanlist::chan, and channel_find_locked().
Referenced by next_channel().
01306 { 01307 return channel_find_locked(chan, NULL, 0, context, exten); 01308 }
struct ast_channel* ast_walk_channel_by_name_prefix_locked | ( | const struct ast_channel * | chan, | |
const char * | name, | |||
const int | namelen | |||
) |
Get channel by name or uniqueid prefix (locks channel).
Definition at line 1291 of file channel.c.
References chanlist::chan, and channel_find_locked().
Referenced by my_ast_get_channel_by_name_locked(), next_channel(), and softhangup_exec().
01293 { 01294 return channel_find_locked(chan, name, namelen, NULL, NULL); 01295 }
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.
chan | destination channel of the frame | |
frame | frame that will be written |
Definition at line 3392 of file channel.c.
References ast_channel::_softhangup, AST_AUDIOHOOK_DIRECTION_WRITE, ast_audiohook_write_list(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_check_hangup(), ast_clear_flag, AST_CONTROL_UNHOLD, ast_deactivate_generator(), ast_debug, ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_WRITE_INT, AST_FLAG_ZOMBIE, ast_format_rate(), AST_FORMAT_T140, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_frame_dump(), AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_frisolate(), AST_LIST_NEXT, ast_log(), AST_MONITOR_RUNNING, ast_seekstream(), ast_senddigit_begin(), ast_senddigit_end(), AST_SOFTHANGUP_DEV, ast_test_flag, ast_translate(), ast_writestream(), ast_channel::audiohooks, calc_monitor_jump(), chanlist::chan, CHECK_BLOCKING, ast_frame::data, ast_frame::datalen, DEBUGCHAN_FLAG, f, ast_filestream::fmt, ast_format::format, ast_channel::fout, FRAMECOUNT_INC, ast_frame::frametype, ast_channel::generatordata, ast_channel_tech::indicate, ast_channel::insmpl, ast_frame::len, LOG_WARNING, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::name, chanlist::next, ast_channel::outsmpl, ast_frame::ptr, ast_channel::rawwriteformat, ast_channel_monitor::read_stream, ast_frame::samples, SEEK_FORCECUR, send_dtmf_event(), ast_channel_tech::send_html, ast_channel_tech::send_text, ast_channel_monitor::state, ast_frame::subclass, ast_channel::tech, ast_channel_tech::write, ast_channel_monitor::write_stream, ast_channel_tech::write_text, ast_channel_tech::write_video, and ast_channel::writetrans.
Referenced by adsi_careful_send(), agent_write(), ast_feature_request_and_dial(), ast_prod(), ast_readaudio_callback(), ast_readvideo_callback(), ast_udptl_bridge(), ast_write_video(), bridge_native_loop(), conf_queue_dtmf(), conf_run(), dahdi_bridge(), dictate_exec(), echo_exec(), fax_generator_generate(), function_ilink(), gen_generate(), handle_jack_audio(), handle_link_data(), jb_get_and_deliver(), linear_generator(), milliwatt_generate(), misdn_bridge(), moh_files_generator(), moh_generate(), mp3_exec(), NBScat_exec(), rpt(), send_link_dtmf(), send_link_keyquery(), send_tone_burst(), send_usb_txt(), send_waveform_to_channel(), silence_generator_generate(), spy_generate(), t38_tx_packet_handler(), and wait_for_answer().
03393 { 03394 int res = -1; 03395 struct ast_frame *f = NULL; 03396 int count = 0; 03397 03398 /*Deadlock avoidance*/ 03399 while(ast_channel_trylock(chan)) { 03400 /*cannot goto done since the channel is not locked*/ 03401 if(count++ > 10) { 03402 ast_debug(1, "Deadlock avoided for write to channel '%s'\n", chan->name); 03403 return 0; 03404 } 03405 usleep(1); 03406 } 03407 /* Stop if we're a zombie or need a soft hangup */ 03408 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) 03409 goto done; 03410 03411 /* Handle any pending masquerades */ 03412 if (chan->masq && ast_do_masquerade(chan)) { 03413 ast_log(LOG_WARNING, "Failed to perform masquerade\n"); 03414 goto done; 03415 } 03416 if (chan->masqr) { 03417 res = 0; /* XXX explain, why 0 ? */ 03418 goto done; 03419 } 03420 if (chan->generatordata) { 03421 if (ast_test_flag(chan, AST_FLAG_WRITE_INT)) 03422 ast_deactivate_generator(chan); 03423 else { 03424 if (fr->frametype == AST_FRAME_DTMF_END) { 03425 /* There is a generator running while we're in the middle of a digit. 03426 * It's probably inband DTMF, so go ahead and pass it so it can 03427 * stop the generator */ 03428 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03429 ast_channel_unlock(chan); 03430 res = ast_senddigit_end(chan, fr->subclass, fr->len); 03431 ast_channel_lock(chan); 03432 CHECK_BLOCKING(chan); 03433 } else if (fr->frametype == AST_FRAME_CONTROL && fr->subclass == AST_CONTROL_UNHOLD) { 03434 /* This is a side case where Echo is basically being called and the person put themselves on hold and took themselves off hold */ 03435 res = (chan->tech->indicate == NULL) ? 0 : 03436 chan->tech->indicate(chan, fr->subclass, fr->data.ptr, fr->datalen); 03437 } 03438 res = 0; /* XXX explain, why 0 ? */ 03439 goto done; 03440 } 03441 } 03442 /* High bit prints debugging */ 03443 if (chan->fout & DEBUGCHAN_FLAG) 03444 ast_frame_dump(chan->name, fr, ">>"); 03445 CHECK_BLOCKING(chan); 03446 switch (fr->frametype) { 03447 case AST_FRAME_CONTROL: 03448 res = (chan->tech->indicate == NULL) ? 0 : 03449 chan->tech->indicate(chan, fr->subclass, fr->data.ptr, fr->datalen); 03450 break; 03451 case AST_FRAME_DTMF_BEGIN: 03452 if (chan->audiohooks) { 03453 struct ast_frame *old_frame = fr; 03454 fr = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr); 03455 if (old_frame != fr) 03456 f = fr; 03457 } 03458 send_dtmf_event(chan, "Sent", fr->subclass, "Yes", "No"); 03459 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03460 ast_channel_unlock(chan); 03461 res = ast_senddigit_begin(chan, fr->subclass); 03462 ast_channel_lock(chan); 03463 CHECK_BLOCKING(chan); 03464 break; 03465 case AST_FRAME_DTMF_END: 03466 if (chan->audiohooks) { 03467 struct ast_frame *new_frame = fr; 03468 03469 new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr); 03470 if (new_frame != fr) { 03471 ast_frfree(new_frame); 03472 } 03473 } 03474 send_dtmf_event(chan, "Sent", fr->subclass, "No", "Yes"); 03475 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03476 ast_channel_unlock(chan); 03477 res = ast_senddigit_end(chan, fr->subclass, fr->len); 03478 ast_channel_lock(chan); 03479 CHECK_BLOCKING(chan); 03480 break; 03481 case AST_FRAME_TEXT: 03482 if (fr->subclass == AST_FORMAT_T140) { 03483 res = (chan->tech->write_text == NULL) ? 0 : 03484 chan->tech->write_text(chan, fr); 03485 } else { 03486 res = (chan->tech->send_text == NULL) ? 0 : 03487 chan->tech->send_text(chan, (char *) fr->data.ptr); 03488 } 03489 break; 03490 case AST_FRAME_HTML: 03491 res = (chan->tech->send_html == NULL) ? 0 : 03492 chan->tech->send_html(chan, fr->subclass, (char *) fr->data.ptr, fr->datalen); 03493 break; 03494 case AST_FRAME_VIDEO: 03495 /* XXX Handle translation of video codecs one day XXX */ 03496 res = (chan->tech->write_video == NULL) ? 0 : 03497 chan->tech->write_video(chan, fr); 03498 break; 03499 case AST_FRAME_MODEM: 03500 res = (chan->tech->write == NULL) ? 0 : 03501 chan->tech->write(chan, fr); 03502 break; 03503 case AST_FRAME_VOICE: 03504 if (chan->tech->write == NULL) 03505 break; /*! \todo XXX should return 0 maybe ? */ 03506 03507 /* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */ 03508 if (fr->subclass == chan->rawwriteformat) 03509 f = fr; 03510 else 03511 f = (chan->writetrans) ? ast_translate(chan->writetrans, fr, 0) : fr; 03512 03513 if (!f) { 03514 res = 0; 03515 break; 03516 } 03517 03518 if (chan->audiohooks) { 03519 struct ast_frame *prev = NULL, *new_frame, *cur, *dup; 03520 int freeoldlist = 0; 03521 03522 if (f != fr) { 03523 freeoldlist = 1; 03524 } 03525 03526 /* Since ast_audiohook_write may return a new frame, and the cur frame is 03527 * an item in a list of frames, create a new list adding each cur frame back to it 03528 * regardless if the cur frame changes or not. */ 03529 for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) { 03530 new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, cur); 03531 03532 /* if this frame is different than cur, preserve the end of the list, 03533 * free the old frames, and set cur to be the new frame */ 03534 if (new_frame != cur) { 03535 03536 /* doing an ast_frisolate here seems silly, but we are not guaranteed the new_frame 03537 * isn't part of local storage, meaning if ast_audiohook_write is called multiple 03538 * times it may override the previous frame we got from it unless we dup it */ 03539 if ((dup = ast_frisolate(new_frame))) { 03540 AST_LIST_NEXT(dup, frame_list) = AST_LIST_NEXT(cur, frame_list); 03541 if (freeoldlist) { 03542 AST_LIST_NEXT(cur, frame_list) = NULL; 03543 ast_frfree(cur); 03544 } 03545 cur = dup; 03546 } 03547 } 03548 03549 /* now, regardless if cur is new or not, add it to the new list, 03550 * if the new list has not started, cur will become the first item. */ 03551 if (prev) { 03552 AST_LIST_NEXT(prev, frame_list) = cur; 03553 } else { 03554 f = cur; /* set f to be the beginning of our new list */ 03555 } 03556 prev = cur; 03557 } 03558 } 03559 03560 /* If Monitor is running on this channel, then we have to write frames out there too */ 03561 /* the translator on chan->writetrans may have returned multiple frames 03562 from the single frame we passed in; if so, feed each one of them to the 03563 monitor */ 03564 if (chan->monitor && chan->monitor->write_stream) { 03565 struct ast_frame *cur; 03566 03567 for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) { 03568 /* XXX must explain this code */ 03569 #ifndef MONITOR_CONSTANT_DELAY 03570 int jump = chan->insmpl - chan->outsmpl - 4 * cur->samples; 03571 if (jump >= 0) { 03572 jump = calc_monitor_jump((chan->insmpl - chan->outsmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format)); 03573 if (ast_seekstream(chan->monitor->write_stream, jump, SEEK_FORCECUR) == -1) 03574 ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n"); 03575 chan->outsmpl += (chan->insmpl - chan->outsmpl) + cur->samples; 03576 } else { 03577 chan->outsmpl += cur->samples; 03578 } 03579 #else 03580 int jump = calc_monitor_jump((chan->insmpl - chan->outsmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format)); 03581 if (jump - MONITOR_DELAY >= 0) { 03582 if (ast_seekstream(chan->monitor->write_stream, jump - cur->samples, SEEK_FORCECUR) == -1) 03583 ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n"); 03584 chan->outsmpl += chan->insmpl - chan->outsmpl; 03585 } else { 03586 chan->outsmpl += cur->samples; 03587 } 03588 #endif 03589 if (chan->monitor->state == AST_MONITOR_RUNNING) { 03590 if (ast_writestream(chan->monitor->write_stream, cur) < 0) 03591 ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n"); 03592 } 03593 } 03594 } 03595 03596 /* the translator on chan->writetrans may have returned multiple frames 03597 from the single frame we passed in; if so, feed each one of them to the 03598 channel, freeing each one after it has been written */ 03599 if ((f != fr) && AST_LIST_NEXT(f, frame_list)) { 03600 struct ast_frame *cur, *next; 03601 unsigned int skip = 0; 03602 03603 for (cur = f, next = AST_LIST_NEXT(cur, frame_list); 03604 cur; 03605 cur = next, next = cur ? AST_LIST_NEXT(cur, frame_list) : NULL) { 03606 if (!skip) { 03607 if ((res = chan->tech->write(chan, cur)) < 0) { 03608 chan->_softhangup |= AST_SOFTHANGUP_DEV; 03609 skip = 1; 03610 } else if (next) { 03611 /* don't do this for the last frame in the list, 03612 as the code outside the loop will do it once 03613 */ 03614 chan->fout = FRAMECOUNT_INC(chan->fout); 03615 } 03616 } 03617 ast_frfree(cur); 03618 } 03619 03620 /* reset f so the code below doesn't attempt to free it */ 03621 f = NULL; 03622 } else { 03623 res = chan->tech->write(chan, f); 03624 } 03625 break; 03626 case AST_FRAME_NULL: 03627 case AST_FRAME_IAX: 03628 /* Ignore these */ 03629 res = 0; 03630 break; 03631 default: 03632 /* At this point, fr is the incoming frame and f is NULL. Channels do 03633 * not expect to get NULL as a frame pointer and will segfault. Hence, 03634 * we output the original frame passed in. */ 03635 res = chan->tech->write(chan, fr); 03636 break; 03637 } 03638 03639 if (f && f != fr) 03640 ast_frfree(f); 03641 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03642 03643 /* Consider a write failure to force a soft hangup */ 03644 if (res < 0) { 03645 chan->_softhangup |= AST_SOFTHANGUP_DEV; 03646 } else { 03647 chan->fout = FRAMECOUNT_INC(chan->fout); 03648 } 03649 done: 03650 ast_channel_unlock(chan); 03651 return res; 03652 }
int ast_write_video | ( | struct ast_channel * | chan, | |
struct ast_frame * | frame | |||
) |
Write video frame to a channel This function writes the given frame to the indicated channel.
chan | destination channel of the frame | |
frame | frame that will be written |
Definition at line 3381 of file channel.c.
References ast_write(), chanlist::chan, ast_channel::tech, and ast_channel_tech::write_video.
03382 { 03383 int res; 03384 if (!chan->tech->write_video) 03385 return 0; 03386 res = ast_write(chan, fr); 03387 if (!res) 03388 res = 1; 03389 return res; 03390 }
static void bridge_play_sounds | ( | struct ast_channel * | c0, | |
struct ast_channel * | c1 | |||
) | [static] |
Definition at line 5020 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_strdupa, bridge_playfile(), pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), and s.
Referenced by ast_channel_bridge().
05021 { 05022 const char *s, *sound; 05023 05024 /* See if we need to play an audio file to any side of the bridge */ 05025 05026 ast_channel_lock(c0); 05027 if ((s = pbx_builtin_getvar_helper(c0, "BRIDGE_PLAY_SOUND"))) { 05028 sound = ast_strdupa(s); 05029 ast_channel_unlock(c0); 05030 bridge_playfile(c0, c1, sound, 0); 05031 pbx_builtin_setvar_helper(c0, "BRIDGE_PLAY_SOUND", NULL); 05032 } else { 05033 ast_channel_unlock(c0); 05034 } 05035 05036 ast_channel_lock(c1); 05037 if ((s = pbx_builtin_getvar_helper(c1, "BRIDGE_PLAY_SOUND"))) { 05038 sound = ast_strdupa(s); 05039 ast_channel_unlock(c1); 05040 bridge_playfile(c1, c0, sound, 0); 05041 pbx_builtin_setvar_helper(c1, "BRIDGE_PLAY_SOUND", NULL); 05042 } else { 05043 ast_channel_unlock(c1); 05044 } 05045 }
static void bridge_playfile | ( | struct ast_channel * | chan, | |
struct ast_channel * | peer, | |||
const char * | sound, | |||
int | remain | |||
) | [static] |
Definition at line 4734 of file channel.c.
References ast_autoservice_start(), ast_autoservice_stop(), AST_DIGIT_ANY, ast_say_number(), ast_stream_and_wait(), chanlist::chan, and sec.
Referenced by ast_channel_bridge(), and bridge_play_sounds().
04735 { 04736 int min = 0, sec = 0, check; 04737 04738 check = ast_autoservice_start(peer); 04739 if (check) 04740 return; 04741 04742 if (remain > 0) { 04743 if (remain / 60 > 1) { 04744 min = remain / 60; 04745 sec = remain % 60; 04746 } else { 04747 sec = remain; 04748 } 04749 } 04750 04751 if (!strcmp(sound,"timeleft")) { /* Queue support */ 04752 ast_stream_and_wait(chan, "vm-youhave", ""); 04753 if (min) { 04754 ast_say_number(chan, min, AST_DIGIT_ANY, chan->language, NULL); 04755 ast_stream_and_wait(chan, "queue-minutes", ""); 04756 } 04757 if (sec) { 04758 ast_say_number(chan, sec, AST_DIGIT_ANY, chan->language, NULL); 04759 ast_stream_and_wait(chan, "queue-seconds", ""); 04760 } 04761 } else { 04762 ast_stream_and_wait(chan, sound, ""); 04763 } 04764 04765 ast_autoservice_stop(peer); 04766 }
static int calc_monitor_jump | ( | int | samples, | |
int | sample_rate, | |||
int | seek_rate | |||
) | [inline, static] |
calculates the number of samples to jump forward with in a monitor stream.
number | of samples to seek forward after rate conversion. |
Definition at line 2605 of file channel.c.
Referenced by __ast_read(), and ast_write().
02606 { 02607 int diff = sample_rate - seek_rate; 02608 02609 if (diff > 0) { 02610 samples = samples / (float) (sample_rate / seek_rate); 02611 } else if (diff < 0) { 02612 samples = samples * (float) (seek_rate / sample_rate); 02613 } 02614 02615 return samples; 02616 }
static struct ast_channel* channel_find_locked | ( | const struct ast_channel * | prev, | |
const char * | name, | |||
const int | namelen, | |||
const char * | context, | |||
const char * | exten | |||
) | [static] |
Helper function to find channels.
It supports these modes:
prev != NULL : get channel next in list after prev name != NULL : get channel with matching name name != NULL && namelen != 0 : get channel whose name starts with prefix exten != NULL : get channel whose exten or macroexten matches context != NULL && exten != NULL : get channel whose context or macrocontext
It returns with the channel's lock held. If getting the individual lock fails, unlock and retry quickly up to 10 times, then give up.
XXX also note that accessing fields (e.g. c->name in ast_log()) can only be done with the lock held or someone could delete the object while we work on it. This causes some ugliness in the code. Note that removing the first ast_log() may be harmful, as it would shorten the retry period and possibly cause failures. We should definitely go for a better scheme that is deadlock-free.
Definition at line 1189 of file channel.c.
References ast_channel_trylock, ast_debug, AST_RWLIST_NEXT, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_channel::context, ast_channel::exten, ast_channel::macrocontext, ast_channel::macroexten, msg, ast_channel::name, and ast_channel::uniqueid.
Referenced by ast_channel_walk_locked(), ast_get_channel_by_exten_locked(), ast_get_channel_by_name_locked(), ast_get_channel_by_name_prefix_locked(), ast_walk_channel_by_exten_locked(), and ast_walk_channel_by_name_prefix_locked().
01192 { 01193 const char *msg = prev ? "deadlock" : "initial deadlock"; 01194 int retries; 01195 struct ast_channel *c; 01196 const struct ast_channel *_prev = prev; 01197 01198 for (retries = 0; retries < 200; retries++) { 01199 int done; 01200 /* Reset prev on each retry. See note below for the reason. */ 01201 prev = _prev; 01202 AST_RWLIST_RDLOCK(&channels); 01203 AST_RWLIST_TRAVERSE(&channels, c, chan_list) { 01204 if (prev) { /* look for last item, first, before any evaluation */ 01205 if (c != prev) /* not this one */ 01206 continue; 01207 /* found, prepare to return c->next */ 01208 if ((c = AST_RWLIST_NEXT(c, chan_list)) == NULL) break; 01209 /*!\note 01210 * We're done searching through the list for the previous item. 01211 * Any item after this point, we want to evaluate for a match. 01212 * If we didn't set prev to NULL here, then we would only 01213 * return matches for the first matching item (since the above 01214 * "if (c != prev)" would not permit any other potential 01215 * matches to reach the additional matching logic, below). 01216 * Instead, it would just iterate until it once again found the 01217 * original match, then iterate down to the end of the list and 01218 * quit. 01219 */ 01220 prev = NULL; 01221 } 01222 if (name) { /* want match by name */ 01223 if ((!namelen && strcasecmp(c->name, name) && strcmp(c->uniqueid, name)) || 01224 (namelen && strncasecmp(c->name, name, namelen))) 01225 continue; /* name match failed */ 01226 } else if (exten) { 01227 if (context && strcasecmp(c->context, context) && 01228 strcasecmp(c->macrocontext, context)) 01229 continue; /* context match failed */ 01230 if (strcasecmp(c->exten, exten) && 01231 strcasecmp(c->macroexten, exten)) 01232 continue; /* exten match failed */ 01233 } 01234 /* if we get here, c points to the desired record */ 01235 break; 01236 } 01237 /* exit if chan not found or mutex acquired successfully */ 01238 /* this is slightly unsafe, as we _should_ hold the lock to access c->name */ 01239 done = c == NULL || ast_channel_trylock(c) == 0; 01240 if (!done) { 01241 ast_debug(1, "Avoiding %s for channel '%p'\n", msg, c); 01242 if (retries == 199) { 01243 /* We are about to fail due to a deadlock, so report this 01244 * while we still have the list lock. 01245 */ 01246 ast_debug(1, "Failure, could not lock '%p' after %d retries!\n", c, retries); 01247 /* As we have deadlocked, we will skip this channel and 01248 * see if there is another match. 01249 * NOTE: No point doing this for a full-name match, 01250 * as there can be no more matches. 01251 */ 01252 if (!(name && !namelen)) { 01253 prev = c; 01254 retries = -1; 01255 } 01256 } 01257 } 01258 AST_RWLIST_UNLOCK(&channels); 01259 if (done) 01260 return c; 01261 /* If we reach this point we basically tried to lock a channel and failed. Instead of 01262 * starting from the beginning of the list we can restore our saved pointer to the previous 01263 * channel and start from there. 01264 */ 01265 prev = _prev; 01266 usleep(1); /* give other threads a chance before retrying */ 01267 } 01268 01269 return NULL; 01270 }
const char* channelreloadreason2txt | ( | enum channelreloadreason | reason | ) |
Convert enum channelreloadreason to text string for manager event.
\ brief Convert channel reloadreason (ENUM) to text string for manager event
Definition at line 5676 of file channel.c.
References CHANNEL_CLI_RELOAD, CHANNEL_MODULE_LOAD, and CHANNEL_MODULE_RELOAD.
05677 { 05678 switch (reason) { 05679 case CHANNEL_MODULE_LOAD: 05680 return "LOAD (Channel module load)"; 05681 05682 case CHANNEL_MODULE_RELOAD: 05683 return "RELOAD (Channel module reload)"; 05684 05685 case CHANNEL_CLI_RELOAD: 05686 return "CLIRELOAD (Channel module reload by CLI command)"; 05687 05688 default: 05689 return "MANAGERRELOAD (Channel module reload by manager)"; 05690 } 05691 };
static void clone_variables | ( | struct ast_channel * | original, | |
struct ast_channel * | clonechan | |||
) | [static] |
Clone channel variables from 'clone' channel into 'original' channel.
All variables except those related to app_groupcount are cloned. Variables are actually _removed_ from 'clone' channel, presumably because it will subsequently be destroyed.
Definition at line 4343 of file channel.c.
References AST_LIST_APPEND_LIST, AST_LIST_FIRST, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_var_assign(), ast_var_t::entries, ast_var_t::name, ast_var_t::value, and ast_channel::varshead.
Referenced by ast_do_masquerade().
04344 { 04345 struct ast_var_t *current, *newvar; 04346 /* Append variables from clone channel into original channel */ 04347 /* XXX Is this always correct? We have to in order to keep MACROS working XXX */ 04348 if (AST_LIST_FIRST(&clonechan->varshead)) 04349 AST_LIST_APPEND_LIST(&original->varshead, &clonechan->varshead, entries); 04350 04351 /* then, dup the varshead list into the clone */ 04352 04353 AST_LIST_TRAVERSE(&original->varshead, current, entries) { 04354 newvar = ast_var_assign(current->name, current->value); 04355 if (newvar) 04356 AST_LIST_INSERT_TAIL(&clonechan->varshead, newvar, entries); 04357 } 04358 }
static char* complete_channeltypes | ( | struct ast_cli_args * | a | ) | [static] |
Definition at line 246 of file channel.c.
References AST_LIST_TRAVERSE, ast_strdup, chanlist::list, ast_cli_args::n, ast_cli_args::pos, chanlist::tech, ast_channel_tech::type, and ast_cli_args::word.
Referenced by handle_cli_core_show_channeltype().
00247 { 00248 struct chanlist *cl; 00249 int which = 0; 00250 int wordlen; 00251 char *ret = NULL; 00252 00253 if (a->pos != 3) 00254 return NULL; 00255 00256 wordlen = strlen(a->word); 00257 00258 AST_LIST_TRAVERSE(&backends, cl, list) { 00259 if (!strncasecmp(a->word, cl->tech->type, wordlen) && ++which > a->n) { 00260 ret = ast_strdup(cl->tech->type); 00261 break; 00262 } 00263 } 00264 00265 return ret; 00266 }
static void free_cid | ( | struct ast_callerid * | cid | ) | [static] |
Definition at line 1355 of file channel.c.
References ast_free, ast_callerid::cid_ani, ast_callerid::cid_dnid, ast_callerid::cid_name, ast_callerid::cid_num, and ast_callerid::cid_rdnis.
Referenced by ast_channel_free().
01356 { 01357 if (cid->cid_dnid) 01358 ast_free(cid->cid_dnid); 01359 if (cid->cid_num) 01360 ast_free(cid->cid_num); 01361 if (cid->cid_name) 01362 ast_free(cid->cid_name); 01363 if (cid->cid_ani) 01364 ast_free(cid->cid_ani); 01365 if (cid->cid_rdnis) 01366 ast_free(cid->cid_rdnis); 01367 cid->cid_dnid = cid->cid_num = cid->cid_name = cid->cid_ani = cid->cid_rdnis = NULL; 01368 }
static void free_translation | ( | struct ast_channel * | clonechan | ) | [static] |
Definition at line 1656 of file channel.c.
References ast_translator_free_path(), ast_channel::nativeformats, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readtrans, and ast_channel::writetrans.
Referenced by ast_do_masquerade(), and ast_hangup().
01657 { 01658 if (clonechan->writetrans) 01659 ast_translator_free_path(clonechan->writetrans); 01660 if (clonechan->readtrans) 01661 ast_translator_free_path(clonechan->readtrans); 01662 clonechan->writetrans = NULL; 01663 clonechan->readtrans = NULL; 01664 clonechan->rawwriteformat = clonechan->nativeformats; 01665 clonechan->rawreadformat = clonechan->nativeformats; 01666 }
static int generator_force | ( | const void * | data | ) | [static] |
Definition at line 1950 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_deactivate_generator(), ast_debug, AST_FORMAT_AUDIO_MASK, ast_format_rate(), and chanlist::chan.
Referenced by ast_activate_generator(), and ast_read_generator_actions().
01951 { 01952 /* Called if generator doesn't have data */ 01953 void *tmp; 01954 int res; 01955 int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples) = NULL; 01956 struct ast_channel *chan = (struct ast_channel *)data; 01957 01958 ast_channel_lock(chan); 01959 tmp = chan->generatordata; 01960 chan->generatordata = NULL; 01961 if (chan->generator) 01962 generate = chan->generator->generate; 01963 ast_channel_unlock(chan); 01964 01965 if (!tmp || !generate) 01966 return 0; 01967 01968 res = generate(chan, tmp, 0, ast_format_rate(chan->writeformat & AST_FORMAT_AUDIO_MASK) / 50); 01969 01970 chan->generatordata = tmp; 01971 01972 if (res) { 01973 ast_debug(1, "Auto-deactivating generator\n"); 01974 ast_deactivate_generator(chan); 01975 } 01976 01977 return 0; 01978 }
static void handle_cause | ( | int | cause, | |
int * | outstate | |||
) | [static] |
Definition at line 3747 of file channel.c.
References AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, AST_CONTROL_BUSY, and AST_CONTROL_CONGESTION.
Referenced by __ast_request_and_dial(), ast_call_forward(), dial_exec_full(), do_forward(), and wait_for_answer().
03748 { 03749 if (outstate) { 03750 /* compute error and return */ 03751 if (cause == AST_CAUSE_BUSY) 03752 *outstate = AST_CONTROL_BUSY; 03753 else if (cause == AST_CAUSE_CONGESTION) 03754 *outstate = AST_CONTROL_CONGESTION; 03755 else 03756 *outstate = 0; 03757 } 03758 }
static char* handle_cli_core_show_channeltype | ( | struct ast_cli_entry * | e, | |
int | cmd, | |||
struct ast_cli_args * | a | |||
) | [static] |
Show details about a channel driver - CLI command.
Definition at line 269 of file channel.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_channel_tech::capabilities, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_channeltypes(), ast_channel_tech::devicestate, ast_cli_args::fd, ast_channel_tech::indicate, chanlist::list, ast_channel_tech::send_digit_begin, ast_channel_tech::send_digit_end, ast_channel_tech::send_html, ast_channel_tech::send_image, ast_channel_tech::send_text, chanlist::tech, ast_channel_tech::transfer, ast_channel_tech::type, and ast_cli_entry::usage.
00270 { 00271 struct chanlist *cl = NULL; 00272 00273 switch (cmd) { 00274 case CLI_INIT: 00275 e->command = "core show channeltype"; 00276 e->usage = 00277 "Usage: core show channeltype <name>\n" 00278 " Show details about the specified channel type, <name>.\n"; 00279 return NULL; 00280 case CLI_GENERATE: 00281 return complete_channeltypes(a); 00282 } 00283 00284 if (a->argc != 4) 00285 return CLI_SHOWUSAGE; 00286 00287 AST_RWLIST_RDLOCK(&channels); 00288 00289 AST_LIST_TRAVERSE(&backends, cl, list) { 00290 if (!strncasecmp(cl->tech->type, a->argv[3], strlen(cl->tech->type))) 00291 break; 00292 } 00293 00294 00295 if (!cl) { 00296 ast_cli(a->fd, "\n%s is not a registered channel driver.\n", a->argv[3]); 00297 AST_RWLIST_UNLOCK(&channels); 00298 return CLI_FAILURE; 00299 } 00300 00301 ast_cli(a->fd, 00302 "-- Info about channel driver: %s --\n" 00303 " Device State: %s\n" 00304 " Indication: %s\n" 00305 " Transfer : %s\n" 00306 " Capabilities: %d\n" 00307 " Digit Begin: %s\n" 00308 " Digit End: %s\n" 00309 " Send HTML : %s\n" 00310 " Image Support: %s\n" 00311 " Text Support: %s\n", 00312 cl->tech->type, 00313 (cl->tech->devicestate) ? "yes" : "no", 00314 (cl->tech->indicate) ? "yes" : "no", 00315 (cl->tech->transfer) ? "yes" : "no", 00316 (cl->tech->capabilities) ? cl->tech->capabilities : -1, 00317 (cl->tech->send_digit_begin) ? "yes" : "no", 00318 (cl->tech->send_digit_end) ? "yes" : "no", 00319 (cl->tech->send_html) ? "yes" : "no", 00320 (cl->tech->send_image) ? "yes" : "no", 00321 (cl->tech->send_text) ? "yes" : "no" 00322 00323 ); 00324 00325 AST_RWLIST_UNLOCK(&channels); 00326 return CLI_SUCCESS; 00327 }
static char* handle_cli_core_show_channeltypes | ( | struct ast_cli_entry * | e, | |
int | cmd, | |||
struct ast_cli_args * | a | |||
) | [static] |
Show channel types - CLI command.
Definition at line 203 of file channel.c.
References ast_cli_args::argc, ast_cli(), AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_channel_tech::description, ast_channel_tech::devicestate, ast_cli_args::fd, FORMAT, ast_channel_tech::indicate, chanlist::list, chanlist::tech, ast_channel_tech::transfer, ast_channel_tech::type, and ast_cli_entry::usage.
00204 { 00205 #define FORMAT "%-10.10s %-40.40s %-12.12s %-12.12s %-12.12s\n" 00206 struct chanlist *cl; 00207 int count_chan = 0; 00208 00209 switch (cmd) { 00210 case CLI_INIT: 00211 e->command = "core show channeltypes"; 00212 e->usage = 00213 "Usage: core show channeltypes\n" 00214 " Lists available channel types registered in your\n" 00215 " Asterisk server.\n"; 00216 return NULL; 00217 case CLI_GENERATE: 00218 return NULL; 00219 } 00220 00221 if (a->argc != 3) 00222 return CLI_SHOWUSAGE; 00223 00224 ast_cli(a->fd, FORMAT, "Type", "Description", "Devicestate", "Indications", "Transfer"); 00225 ast_cli(a->fd, FORMAT, "----------", "-----------", "-----------", "-----------", "--------"); 00226 00227 AST_RWLIST_RDLOCK(&channels); 00228 00229 AST_LIST_TRAVERSE(&backends, cl, list) { 00230 ast_cli(a->fd, FORMAT, cl->tech->type, cl->tech->description, 00231 (cl->tech->devicestate) ? "yes" : "no", 00232 (cl->tech->indicate) ? "yes" : "no", 00233 (cl->tech->transfer) ? "yes" : "no"); 00234 count_chan++; 00235 } 00236 00237 AST_RWLIST_UNLOCK(&channels); 00238 00239 ast_cli(a->fd, "----------\n%d channel drivers registered.\n", count_chan); 00240 00241 return CLI_SUCCESS; 00242 00243 #undef FORMAT 00244 }
static int attribute_const is_visible_indication | ( | enum ast_control_frame_type | condition | ) | [static] |
Definition at line 3095 of file channel.c.
References _XXX_AST_CONTROL_T38, AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_OFFHOOK, AST_CONTROL_OPTION, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_RING, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, and AST_CONTROL_WINK.
Referenced by ast_indicate_data().
03096 { 03097 /* Don't include a default case here so that we get compiler warnings 03098 * when a new type is added. */ 03099 03100 switch (condition) { 03101 case AST_CONTROL_PROGRESS: 03102 case AST_CONTROL_PROCEEDING: 03103 case AST_CONTROL_VIDUPDATE: 03104 case AST_CONTROL_SRCUPDATE: 03105 case AST_CONTROL_SRCCHANGE: 03106 case AST_CONTROL_RADIO_KEY: 03107 case AST_CONTROL_RADIO_UNKEY: 03108 case AST_CONTROL_OPTION: 03109 case AST_CONTROL_WINK: 03110 case AST_CONTROL_FLASH: 03111 case AST_CONTROL_OFFHOOK: 03112 case AST_CONTROL_TAKEOFFHOOK: 03113 case AST_CONTROL_ANSWER: 03114 case AST_CONTROL_HANGUP: 03115 case AST_CONTROL_T38_PARAMETERS: 03116 case _XXX_AST_CONTROL_T38: 03117 break; 03118 03119 case AST_CONTROL_CONGESTION: 03120 case AST_CONTROL_BUSY: 03121 case AST_CONTROL_RINGING: 03122 case AST_CONTROL_RING: 03123 case AST_CONTROL_HOLD: 03124 case AST_CONTROL_UNHOLD: 03125 return 1; 03126 } 03127 03128 return 0; 03129 }
static void manager_bridge_event | ( | int | onoff, | |
int | type, | |||
struct ast_channel * | c0, | |||
struct ast_channel * | c1 | |||
) | [static] |
Send manager event for bridge link and unlink events.
onoff | Link/Unlinked | |
type | 1 for core, 2 for native | |
c0 | first channel in bridge | |
c1 | second channel in bridge |
Definition at line 4965 of file channel.c.
References ast_channel::cid, ast_callerid::cid_num, EVENT_FLAG_CALL, manager_event, ast_channel::name, S_OR, and ast_channel::uniqueid.
Referenced by ast_channel_bridge().
04966 { 04967 manager_event(EVENT_FLAG_CALL, "Bridge", 04968 "Bridgestate: %s\r\n" 04969 "Bridgetype: %s\r\n" 04970 "Channel1: %s\r\n" 04971 "Channel2: %s\r\n" 04972 "Uniqueid1: %s\r\n" 04973 "Uniqueid2: %s\r\n" 04974 "CallerID1: %s\r\n" 04975 "CallerID2: %s\r\n", 04976 onoff ? "Link" : "Unlink", 04977 type == 1 ? "core" : "native", 04978 c0->name, c1->name, c0->uniqueid, c1->uniqueid, 04979 S_OR(c0->cid.cid_num, ""), 04980 S_OR(c1->cid.cid_num, "")); 04981 }
static void queue_dtmf_readq | ( | struct ast_channel * | chan, | |
struct ast_frame * | f | |||
) | [inline, static] |
Definition at line 2560 of file channel.c.
References AST_FRAME_DTMF_END, ast_queue_frame(), chanlist::chan, ast_channel::dtmff, f, ast_frame::frametype, ast_frame::len, and ast_frame::subclass.
Referenced by __ast_read().
02561 { 02562 struct ast_frame *fr = &chan->dtmff; 02563 02564 fr->frametype = AST_FRAME_DTMF_END; 02565 fr->subclass = f->subclass; 02566 fr->len = f->len; 02567 02568 /* The only time this function will be called is for a frame that just came 02569 * out of the channel driver. So, we want to stick it on the tail of the 02570 * readq. */ 02571 02572 ast_queue_frame(chan, fr); 02573 }
static void report_new_callerid | ( | const struct ast_channel * | chan | ) | [static] |
Definition at line 4363 of file channel.c.
References ast_describe_caller_presentation(), chanlist::chan, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, ast_callerid::cid_pres, EVENT_FLAG_CALL, manager_event, ast_channel::name, S_OR, and ast_channel::uniqueid.
Referenced by ast_do_masquerade(), and ast_set_callerid().
04364 { 04365 manager_event(EVENT_FLAG_CALL, "NewCallerid", 04366 "Channel: %s\r\n" 04367 "CallerIDNum: %s\r\n" 04368 "CallerIDName: %s\r\n" 04369 "Uniqueid: %s\r\n" 04370 "CID-CallingPres: %d (%s)\r\n", 04371 chan->name, 04372 S_OR(chan->cid.cid_num, ""), 04373 S_OR(chan->cid.cid_name, ""), 04374 chan->uniqueid, 04375 chan->cid.cid_pres, 04376 ast_describe_caller_presentation(chan->cid.cid_pres) 04377 ); 04378 }
static void send_dtmf_event | ( | const struct ast_channel * | chan, | |
const char * | direction, | |||
const char | digit, | |||
const char * | begin, | |||
const char * | end | |||
) | [static] |
Definition at line 2499 of file channel.c.
References chanlist::chan, EVENT_FLAG_DTMF, manager_event, ast_channel::name, and ast_channel::uniqueid.
Referenced by __ast_read(), and ast_write().
02500 { 02501 manager_event(EVENT_FLAG_DTMF, 02502 "DTMF", 02503 "Channel: %s\r\n" 02504 "Uniqueid: %s\r\n" 02505 "Digit: %c\r\n" 02506 "Direction: %s\r\n" 02507 "Begin: %s\r\n" 02508 "End: %s\r\n", 02509 chan->name, chan->uniqueid, digit, direction, begin, end); 02510 }
static int set_format | ( | struct ast_channel * | chan, | |
int | fmt, | |||
int * | rawformat, | |||
int * | format, | |||
struct ast_trans_pvt ** | trans, | |||
const int | direction | |||
) | [static] |
Definition at line 3654 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_debug, AST_FORMAT_AUDIO_MASK, ast_getformatname(), ast_getformatname_multiple(), ast_log(), ast_translator_best_choice(), ast_translator_build_path(), ast_translator_free_path(), chanlist::chan, LOG_WARNING, ast_channel::name, and ast_channel::nativeformats.
Referenced by ast_set_read_format(), and ast_set_write_format().
03656 { 03657 int native; 03658 int res; 03659 char from[200], to[200]; 03660 03661 /* Make sure we only consider audio */ 03662 fmt &= AST_FORMAT_AUDIO_MASK; 03663 03664 native = chan->nativeformats; 03665 03666 if (!fmt || !native) /* No audio requested */ 03667 return 0; /* Let's try a call without any sounds (video, text) */ 03668 03669 /* Find a translation path from the native format to one of the desired formats */ 03670 if (!direction) 03671 /* reading */ 03672 res = ast_translator_best_choice(&fmt, &native); 03673 else 03674 /* writing */ 03675 res = ast_translator_best_choice(&native, &fmt); 03676 03677 if (res < 0) { 03678 ast_log(LOG_WARNING, "Unable to find a codec translation path from %s to %s\n", 03679 ast_getformatname_multiple(from, sizeof(from), native), 03680 ast_getformatname_multiple(to, sizeof(to), fmt)); 03681 return -1; 03682 } 03683 03684 /* Now we have a good choice for both. */ 03685 ast_channel_lock(chan); 03686 03687 if ((*rawformat == native) && (*format == fmt) && ((*rawformat == *format) || (*trans))) { 03688 /* the channel is already in these formats, so nothing to do */ 03689 ast_channel_unlock(chan); 03690 return 0; 03691 } 03692 03693 *rawformat = native; 03694 /* User perspective is fmt */ 03695 *format = fmt; 03696 /* Free any read translation we have right now */ 03697 if (*trans) 03698 ast_translator_free_path(*trans); 03699 /* Build a translation path from the raw format to the desired format */ 03700 if (!direction) 03701 /* reading */ 03702 *trans = ast_translator_build_path(*format, *rawformat); 03703 else 03704 /* writing */ 03705 *trans = ast_translator_build_path(*rawformat, *format); 03706 ast_channel_unlock(chan); 03707 ast_debug(1, "Set channel %s to %s format %s\n", chan->name, 03708 direction ? "write" : "read", ast_getformatname(fmt)); 03709 return 0; 03710 }
static int should_skip_dtmf | ( | struct ast_channel * | chan | ) | [inline, static] |
Determine whether or not we should ignore DTMF in the readq.
Definition at line 2578 of file channel.c.
References AST_FLAG_DEFER_DTMF, AST_FLAG_EMULATE_DTMF, AST_MIN_DTMF_GAP, ast_test_flag, ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), chanlist::chan, and ast_channel::dtmf_tv.
Referenced by __ast_read().
02579 { 02580 if (ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_EMULATE_DTMF)) { 02581 /* We're in the middle of emulating a digit, or DTMF has been 02582 * explicitly deferred. Skip this digit, then. */ 02583 return 1; 02584 } 02585 02586 if (!ast_tvzero(chan->dtmf_tv) && 02587 ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) { 02588 /* We're not in the middle of a digit, but it hasn't been long enough 02589 * since the last digit, so we'll have to skip DTMF for now. */ 02590 return 1; 02591 } 02592 02593 return 0; 02594 }
static void* silence_generator_alloc | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
static int silence_generator_generate | ( | struct ast_channel * | chan, | |
void * | data, | |||
int | len, | |||
int | samples | |||
) | [static] |
Definition at line 5607 of file channel.c.
References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_write(), buf, chan, and ast_frame::frametype.
05608 { 05609 short buf[samples]; 05610 struct ast_frame frame = { 05611 .frametype = AST_FRAME_VOICE, 05612 .subclass = AST_FORMAT_SLINEAR, 05613 .data.ptr = buf, 05614 .samples = samples, 05615 .datalen = sizeof(buf), 05616 }; 05617 05618 memset(buf, 0, sizeof(buf)); 05619 05620 if (ast_write(chan, &frame)) 05621 return -1; 05622 05623 return 0; 05624 }
static void silence_generator_release | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
static void* tonepair_alloc | ( | struct ast_channel * | chan, | |
void * | params | |||
) | [static] |
Definition at line 5363 of file channel.c.
References ast_calloc, AST_FLAG_WRITE_INT, AST_FORMAT_SLINEAR, ast_log(), ast_set_flag, ast_set_write_format(), chan, cos, tonepair_def::duration, tonepair_def::freq1, tonepair_def::freq2, LOG_WARNING, ast_channel::name, tonepair_release(), tonepair_def::vol, and ast_channel::writeformat.
05364 { 05365 struct tonepair_state *ts; 05366 struct tonepair_def *td = params; 05367 05368 if (!(ts = ast_calloc(1, sizeof(*ts)))) 05369 return NULL; 05370 ts->origwfmt = chan->writeformat; 05371 if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) { 05372 ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name); 05373 tonepair_release(NULL, ts); 05374 ts = NULL; 05375 } else { 05376 ts->fac1 = 2.0 * cos(2.0 * M_PI * (td->freq1 / 8000.0)) * 32768.0; 05377 ts->v1_1 = 0; 05378 ts->v2_1 = sin(-4.0 * M_PI * (td->freq1 / 8000.0)) * td->vol; 05379 ts->v3_1 = sin(-2.0 * M_PI * (td->freq1 / 8000.0)) * td->vol; 05380 ts->v2_1 = 0; 05381 ts->fac2 = 2.0 * cos(2.0 * M_PI * (td->freq2 / 8000.0)) * 32768.0; 05382 ts->v2_2 = sin(-4.0 * M_PI * (td->freq2 / 8000.0)) * td->vol; 05383 ts->v3_2 = sin(-2.0 * M_PI * (td->freq2 / 8000.0)) * td->vol; 05384 ts->duration = td->duration; 05385 ts->modulate = 0; 05386 } 05387 /* Let interrupts interrupt :) */ 05388 ast_set_flag(chan, AST_FLAG_WRITE_INT); 05389 return ts; 05390 }
static int tonepair_generator | ( | struct ast_channel * | chan, | |
void * | data, | |||
int | len, | |||
int | samples | |||
) | [static] |
Definition at line 5392 of file channel.c.
References ast_log(), tonepair_state::data, tonepair_state::f, tonepair_state::fac1, tonepair_state::fac2, LOG_WARNING, tonepair_state::modulate, tonepair_state::v1_1, tonepair_state::v1_2, tonepair_state::v2_1, tonepair_state::v2_2, tonepair_state::v3_1, and tonepair_state::v3_2.
05393 { 05394 struct tonepair_state *ts = data; 05395 int x; 05396 05397 /* we need to prepare a frame with 16 * timelen samples as we're 05398 * generating SLIN audio 05399 */ 05400 len = samples * 2; 05401 05402 if (len > sizeof(ts->data) / 2 - 1) { 05403 ast_log(LOG_WARNING, "Can't generate that much data!\n"); 05404 return -1; 05405 } 05406 memset(&ts->f, 0, sizeof(ts->f)); 05407 for (x=0;x<len/2;x++) { 05408 ts->v1_1 = ts->v2_1; 05409 ts->v2_1 = ts->v3_1; 05410 ts->v3_1 = (ts->fac1 * ts->v2_1 >> 15) - ts->v1_1; 05411 05412 ts->v1_2 = ts->v2_2; 05413 ts->v2_2 = ts->v3_2; 05414 ts->v3_2 = (ts->fac2 * ts->v2_2 >> 15) - ts->v1_2; 05415 if (ts->modulate) { 05416 int p; 05417 p = ts->v3_2 - 32768; 05418 if (p < 0) p = -p; 05419 p = ((p * 9) / 10) + 1; 05420 ts->data[x] = (ts->v3_1 * p) >> 15; 05421 } else 05422 ts->data[x] = ts->v3_1 + ts->v3_2; 05423 } 05424 ts->f.frametype = AST_FRAME_VOICE; 05425 ts->f.subclass = AST_FORMAT_SLINEAR; 05426 ts->f.datalen = len; 05427 ts->f.samples = samples; 05428 ts->f.offset = AST_FRIENDLY_OFFSET; 05429 ts->f.data.ptr = ts->data; 05430 ast_write(chan, &ts->f); 05431 ts->pos += x; 05432 if (ts->duration > 0) { 05433 if (ts->pos >= ts->duration * 8) 05434 return -1; 05435 } 05436 return 0; 05437 }
static void tonepair_release | ( | struct ast_channel * | chan, | |
void * | params | |||
) | [static] |
Definition at line 5354 of file channel.c.
References ast_free, ast_set_write_format(), chan, and tonepair_state::origwfmt.
Referenced by tonepair_alloc().
05355 { 05356 struct tonepair_state *ts = params; 05357 05358 if (chan) 05359 ast_set_write_format(chan, ts->origwfmt); 05360 ast_free(ts); 05361 }
static void update_bridge_vars | ( | struct ast_channel * | c0, | |
struct ast_channel * | c1 | |||
) | [static] |
Definition at line 4983 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_strdupa, ast_strlen_zero(), ast_channel_tech::get_pvt_uniqueid, ast_channel::name, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), and ast_channel::tech.
Referenced by ast_channel_bridge().
04984 { 04985 const char *c0_name; 04986 const char *c1_name; 04987 const char *c0_pvtid = NULL; 04988 const char *c1_pvtid = NULL; 04989 04990 ast_channel_lock(c1); 04991 c1_name = ast_strdupa(c1->name); 04992 if (c1->tech->get_pvt_uniqueid) { 04993 c1_pvtid = ast_strdupa(c1->tech->get_pvt_uniqueid(c1)); 04994 } 04995 ast_channel_unlock(c1); 04996 04997 ast_channel_lock(c0); 04998 if (!ast_strlen_zero(pbx_builtin_getvar_helper(c0, "BRIDGEPEER"))) { 04999 pbx_builtin_setvar_helper(c0, "BRIDGEPEER", c1_name); 05000 } 05001 if (c1_pvtid) { 05002 pbx_builtin_setvar_helper(c0, "BRIDGEPVTCALLID", c1_pvtid); 05003 } 05004 c0_name = ast_strdupa(c0->name); 05005 if (c0->tech->get_pvt_uniqueid) { 05006 c0_pvtid = ast_strdupa(c0->tech->get_pvt_uniqueid(c0)); 05007 } 05008 ast_channel_unlock(c0); 05009 05010 ast_channel_lock(c1); 05011 if (!ast_strlen_zero(pbx_builtin_getvar_helper(c1, "BRIDGEPEER"))) { 05012 pbx_builtin_setvar_helper(c1, "BRIDGEPEER", c0_name); 05013 } 05014 if (c0_pvtid) { 05015 pbx_builtin_setvar_helper(c1, "BRIDGEPVTCALLID", c0_pvtid); 05016 } 05017 ast_channel_unlock(c1); 05018 }
void(*) ast_moh_cleanup_ptr(struct ast_channel *) = NULL [static] |
Definition at line 5515 of file channel.c.
Referenced by ast_install_music_functions(), ast_moh_cleanup(), and ast_uninstall_music_functions().
int(*) ast_moh_start_ptr(struct ast_channel *, const char *, const char *) = NULL [static] |
Definition at line 5513 of file channel.c.
Referenced by ast_install_music_functions(), ast_moh_start(), and ast_uninstall_music_functions().
void(*) ast_moh_stop_ptr(struct ast_channel *) = NULL [static] |
Definition at line 5514 of file channel.c.
Referenced by ast_install_music_functions(), ast_moh_stop(), and ast_uninstall_music_functions().
map AST_CAUSE's to readable string representations
Referenced by ast_cause2str(), ast_str2cause(), and dump_cause().
struct ast_cli_entry cli_channel[] [static] |
Initial value:
{ { .handler = handle_cli_core_show_channeltypes , .summary = "List available channel types" ,__VA_ARGS__ }, { .handler = handle_cli_core_show_channeltype , .summary = "Give more details on that channel type" ,__VA_ARGS__ } }
Definition at line 329 of file channel.c.
Referenced by ast_channels_init().
unsigned long global_fin |
The current value of the debug flags is stored in the two variables global_fin and global_fout (declared in main/channel.c)
Definition at line 86 of file channel.c.
Referenced by handle_core_set_debug_channel().
unsigned long global_fout |
struct ast_channel_tech null_tech [static] |
Initial value:
{ .type = "NULL", .description = "Null channel (should not see this)", }
Definition at line 764 of file channel.c.
Referenced by __ast_channel_alloc_ap().
int shutting_down [static] |
struct ast_generator silence_generator [static] |
Initial value:
{ .alloc = silence_generator_alloc, .release = silence_generator_release, .generate = silence_generator_generate, }
Definition at line 5626 of file channel.c.
Referenced by ast_channel_start_silence_generator().
struct ast_threadstorage state2str_threadbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_state2str_threadbuf , .custom_init = NULL , } [static] |
struct ast_generator tonepair [static] |
Initial value:
{ alloc: tonepair_alloc, release: tonepair_release, generate: tonepair_generator, }
Definition at line 5439 of file channel.c.
Referenced by ast_tonepair_start().