Channel Management. More...
#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_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 | plc_ds |
| 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. | |
| 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. | |
| 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) |
| struct 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) |
| static void | adjust_frame_for_plc (struct ast_channel *chan, struct ast_frame *frame, struct ast_datastore *datastore) |
| static void | apply_plc (struct ast_channel *chan, struct ast_frame *frame) |
| 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. | |
| struct 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. | |
| 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. | |
| 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. | |
| 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,...) |
| 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 when to hangup channel. | |
| int | ast_channel_datastore_add (struct ast_channel *chan, struct ast_datastore *datastore) |
| Add a datastore to a channel. | |
| struct ast_datastore * | ast_channel_datastore_alloc (const struct ast_datastore_info *info, const char *uid) |
| Create a channel data store object. | |
| 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. | |
| 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 new telephony channel in Asterisk. | |
| struct ast_channel * | ast_channel_search_locked (int(*is_match)(struct ast_channel *, void *), void *data) |
| Search for a channel based on the passed channel matching callback (first match) and return it, locked. | |
| 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 hangup channel. | |
| struct 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 channel driver. | |
| struct ast_channel * | ast_channel_walk_locked (const struct ast_channel *prev) |
| Browse channels in use. | |
| void | ast_channels_init (void) |
| struct ast_variable * | ast_channeltype_list (void) |
| return an ast_variable list of channeltypes | |
| int | ast_check_hangup (struct ast_channel *chan) |
| Checks 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) |
| Masquerade a channel. | |
| 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) |
| 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. | |
| struct ast_channel * | ast_get_channel_by_name_locked (const char *name) |
| Get channel by name and lock it. | |
| struct ast_channel * | ast_get_channel_by_name_prefix_locked (const char *name, const int namelen) |
| Get channel by name prefix and lock it. | |
| struct ast_channel_tech * | ast_get_channel_tech (const char *name) |
| Get handle to channel driver based on name. | |
| ast_group_t | ast_get_group (const char *s) |
| int | ast_hangup (struct ast_channel *chan) |
| Hangup 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. | |
| int | ast_is_deferrable_frame (const struct ast_frame *frame) |
| Should we keep this frame for later? | |
| 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. | |
| int | ast_plc_reload (void) |
| Reload genericplc configuration value from codecs.conf. | |
| 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 group and pickup group ---. | |
| 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. | |
| 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 for channel. | |
| int | ast_queue_hangup_with_cause (struct ast_channel *chan, int cause) |
| Queue a hangup frame for channel. | |
| int | ast_raw_answer (struct ast_channel *chan, int cdr_answer) |
| Answer a channel. | |
| struct 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) |
| struct 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. | |
| struct ast_channel * | ast_request (const char *type, int format, void *data, int *cause) |
| Requests a channel. | |
| struct 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, look for hangups. | |
| int | ast_safe_sleep_conditional (struct ast_channel *chan, int ms, int(*cond)(void *), void *data) |
| Wait, look for hangups and condition arg. | |
| 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) |
| says digits of a string | |
| int | ast_say_digits (struct ast_channel *chan, int num, const char *ints, const char *lang) |
| says digits | |
| 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) |
| says an enumeration | |
| int | ast_say_number (struct ast_channel *chan, int num, const char *ints, const char *language, const char *options) |
| says a number | |
| 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 a channel, lock. | |
| int | ast_softhangup_nolock (struct ast_channel *chan, int cause) |
| Softly hangup a channel, don't 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 call to dest, if the channel supports transfer. | |
| 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. | |
| struct 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) |
| Wait for x amount of time on a file descriptor to have input. | |
| struct ast_channel * | ast_waitfor_nandfds (struct ast_channel **c, int n, int *fds, int nfds, int *exception, int *outfd, int *ms) |
| Wait for x amount of time on a file descriptor to have input. | |
| 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. | |
| 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. | |
| struct ast_channel * | ast_walk_channel_by_name_prefix_locked (const struct ast_channel *chan, const char *name, const int namelen) |
| Get next channel by name prefix and lock it. | |
| 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 | plc_ds_destroy (void *data) |
| 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 |
| struct { | |
| int cause | |
| const char * desc | |
| const char * name | |
| } | 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 struct ast_datastore_info | plc_ds_info |
| 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 |
Channel Management.
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 |
Definition at line 89 of file channel.c.
Referenced by ast_state2str().
| 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 answers a channel and handles all necessary call setup functions.
| 0 | on success | |
| non-zero | on failure |
Definition at line 1910 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(), errno, frames, ast_frame::frametype, LOG_WARNING, MAX, and ast_frame::subclass.
Referenced by ast_answer(), dial_exec_full(), pbx_builtin_answer(), and pbx_builtin_incomplete().
01911 { 01912 int res = 0; 01913 enum ast_channel_state old_state; 01914 01915 old_state = chan->_state; 01916 if ((res = ast_raw_answer(chan, cdr_answer))) { 01917 return res; 01918 } 01919 01920 switch (old_state) { 01921 case AST_STATE_RINGING: 01922 case AST_STATE_RING: 01923 /* wait for media to start flowing, but don't wait any longer 01924 * than 'delay' or 500 milliseconds, whichever is longer 01925 */ 01926 do { 01927 AST_LIST_HEAD_NOLOCK(, ast_frame) frames; 01928 struct ast_frame *cur, *new; 01929 int ms = MAX(delay, 500); 01930 unsigned int done = 0; 01931 01932 AST_LIST_HEAD_INIT_NOLOCK(&frames); 01933 01934 for (;;) { 01935 ms = ast_waitfor(chan, ms); 01936 if (ms < 0) { 01937 ast_log(LOG_WARNING, "Error condition occurred when polling channel %s for a voice frame: %s\n", chan->name, strerror(errno)); 01938 res = -1; 01939 break; 01940 } 01941 if (ms == 0) { 01942 ast_debug(2, "Didn't receive a media frame from %s within %d ms of answering. Continuing anyway\n", chan->name, MAX(delay, 500)); 01943 break; 01944 } 01945 cur = ast_read(chan); 01946 if (!cur || ((cur->frametype == AST_FRAME_CONTROL) && 01947 (cur->subclass == AST_CONTROL_HANGUP))) { 01948 if (cur) { 01949 ast_frfree(cur); 01950 } 01951 res = -1; 01952 ast_debug(2, "Hangup of channel %s detected in answer routine\n", chan->name); 01953 break; 01954 } 01955 01956 if ((new = ast_frisolate(cur)) != cur) { 01957 ast_frfree(cur); 01958 } 01959 01960 AST_LIST_INSERT_HEAD(&frames, new, frame_list); 01961 01962 /* if a specific delay period was requested, continue 01963 * until that delay has passed. don't stop just because 01964 * incoming media has arrived. 01965 */ 01966 if (delay) { 01967 continue; 01968 } 01969 01970 switch (new->frametype) { 01971 /* all of these frametypes qualify as 'media' */ 01972 case AST_FRAME_VOICE: 01973 case AST_FRAME_VIDEO: 01974 case AST_FRAME_TEXT: 01975 case AST_FRAME_DTMF_BEGIN: 01976 case AST_FRAME_DTMF_END: 01977 case AST_FRAME_IMAGE: 01978 case AST_FRAME_HTML: 01979 case AST_FRAME_MODEM: 01980 done = 1; 01981 break; 01982 case AST_FRAME_CONTROL: 01983 case AST_FRAME_IAX: 01984 case AST_FRAME_NULL: 01985 case AST_FRAME_CNG: 01986 break; 01987 } 01988 01989 if (done) { 01990 break; 01991 } 01992 } 01993 01994 if (res == 0) { 01995 ast_channel_lock(chan); 01996 while ((cur = AST_LIST_REMOVE_HEAD(&frames, frame_list))) { 01997 ast_queue_frame_head(chan, cur); 01998 ast_frfree(cur); 01999 } 02000 ast_channel_unlock(chan); 02001 } 02002 } while (0); 02003 break; 02004 default: 02005 break; 02006 } 02007 02008 return res; 02009 }
| 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, | |||
| ... | ||||
| ) | [read] |
Create a channel structure.
| NULL | failure | |
| non-NULL | successfully allocated channel |
Definition at line 978 of file channel.c.
References __ast_channel_alloc_ap().
00983 { 00984 va_list ap1, ap2; 00985 struct ast_channel *result; 00986 00987 va_start(ap1, name_fmt); 00988 va_start(ap2, name_fmt); 00989 result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context, 00990 amaflag, file, line, function, name_fmt, ap1, ap2); 00991 va_end(ap1); 00992 va_end(ap2); 00993 00994 return result; 00995 }
| 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, read] |
Create a new channel structure.
Definition at line 772 of file channel.c.
References __ast_calloc(), ast_channel::_state, accountcode, ast_channel::alertpipe, ast_channel::amaflags, 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, ast_channel::cdr, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, ast_channel::context, defaultlanguage, errno, EVENT_FLAG_CALL, ast_channel::exten, ast_channel::fds, ast_channel::fin, chanlist::flags, ast_channel::fout, language, ast_channel::lock_dont_use, LOG_WARNING, manager_event, name, null_tech, ast_channel::priority, S_OR, ast_channel::sched, sched_context_create(), sched_context_destroy(), ast_channel::streamid, ast_channel::tech, chanlist::tech, ast_channel::timer, ast_channel::timingfd, and ast_channel::varshead.
Referenced by __ast_channel_alloc(), and ast_channel_alloc().
00776 { 00777 struct ast_channel *tmp; 00778 int x; 00779 int flags; 00780 struct varshead *headp; 00781 char *tech = ""; 00782 00783 /* If shutting down, don't allocate any new channels */ 00784 if (shutting_down) { 00785 ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n"); 00786 return NULL; 00787 } 00788 00789 #if defined(__AST_DEBUG_MALLOC) 00790 if (!(tmp = __ast_calloc(1, sizeof(*tmp), file, line, function))) { 00791 return NULL; 00792 } 00793 #else 00794 if (!(tmp = ast_calloc(1, sizeof(*tmp)))) { 00795 return NULL; 00796 } 00797 #endif 00798 00799 if (!(tmp->sched = sched_context_create())) { 00800 ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n"); 00801 ast_free(tmp); 00802 return NULL; 00803 } 00804 00805 if ((ast_string_field_init(tmp, 128))) { 00806 sched_context_destroy(tmp->sched); 00807 ast_free(tmp); 00808 return NULL; 00809 } 00810 00811 #ifdef HAVE_EPOLL 00812 tmp->epfd = epoll_create(25); 00813 #endif 00814 00815 for (x = 0; x < AST_MAX_FDS; x++) { 00816 tmp->fds[x] = -1; 00817 #ifdef HAVE_EPOLL 00818 tmp->epfd_data[x] = NULL; 00819 #endif 00820 } 00821 00822 if ((tmp->timer = ast_timer_open())) { 00823 needqueue = 0; 00824 tmp->timingfd = ast_timer_fd(tmp->timer); 00825 } else { 00826 tmp->timingfd = -1; 00827 } 00828 00829 if (needqueue) { 00830 if (pipe(tmp->alertpipe)) { 00831 ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe! Try increasing max file descriptors with ulimit -n\n"); 00832 alertpipe_failed: 00833 if (tmp->timer) { 00834 ast_timer_close(tmp->timer); 00835 } 00836 00837 sched_context_destroy(tmp->sched); 00838 ast_string_field_free_memory(tmp); 00839 ast_free(tmp); 00840 return NULL; 00841 } else { 00842 flags = fcntl(tmp->alertpipe[0], F_GETFL); 00843 if (fcntl(tmp->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) { 00844 ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno)); 00845 close(tmp->alertpipe[0]); 00846 close(tmp->alertpipe[1]); 00847 goto alertpipe_failed; 00848 } 00849 flags = fcntl(tmp->alertpipe[1], F_GETFL); 00850 if (fcntl(tmp->alertpipe[1], F_SETFL, flags | O_NONBLOCK) < 0) { 00851 ast_log(LOG_WARNING, "Channel allocation failed: Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno)); 00852 close(tmp->alertpipe[0]); 00853 close(tmp->alertpipe[1]); 00854 goto alertpipe_failed; 00855 } 00856 } 00857 } else /* Make sure we've got it done right if they don't */ 00858 tmp->alertpipe[0] = tmp->alertpipe[1] = -1; 00859 00860 /* Always watch the alertpipe */ 00861 ast_channel_set_fd(tmp, AST_ALERT_FD, tmp->alertpipe[0]); 00862 /* And timing pipe */ 00863 ast_channel_set_fd(tmp, AST_TIMING_FD, tmp->timingfd); 00864 ast_string_field_set(tmp, name, "**Unknown**"); 00865 00866 /* Initial state */ 00867 tmp->_state = state; 00868 00869 tmp->streamid = -1; 00870 00871 tmp->fin = global_fin; 00872 tmp->fout = global_fout; 00873 00874 if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) { 00875 ast_string_field_build(tmp, uniqueid, "%li.%d", (long) time(NULL), 00876 ast_atomic_fetchadd_int(&uniqueint, 1)); 00877 } else { 00878 ast_string_field_build(tmp, uniqueid, "%s-%li.%d", ast_config_AST_SYSTEM_NAME, 00879 (long) time(NULL), ast_atomic_fetchadd_int(&uniqueint, 1)); 00880 } 00881 00882 tmp->cid.cid_name = ast_strdup(cid_name); 00883 tmp->cid.cid_num = ast_strdup(cid_num); 00884 00885 if (!ast_strlen_zero(name_fmt)) { 00886 char *slash; 00887 /* Almost every channel is calling this function, and setting the name via the ast_string_field_build() call. 00888 * And they all use slightly different formats for their name string. 00889 * This means, to set the name here, we have to accept variable args, and call the string_field_build from here. 00890 * This means, that the stringfields must have a routine that takes the va_lists directly, and 00891 * uses them to build the string, instead of forming the va_lists internally from the vararg ... list. 00892 * This new function was written so this can be accomplished. 00893 */ 00894 ast_string_field_build_va(tmp, name, name_fmt, ap1, ap2); 00895 tech = ast_strdupa(tmp->name); 00896 if ((slash = strchr(tech, '/'))) { 00897 *slash = '\0'; 00898 } 00899 } 00900 00901 /* Reminder for the future: under what conditions do we NOT want to track cdrs on channels? */ 00902 00903 /* These 4 variables need to be set up for the cdr_init() to work right */ 00904 if (amaflag) 00905 tmp->amaflags = amaflag; 00906 else 00907 tmp->amaflags = ast_default_amaflags; 00908 00909 if (!ast_strlen_zero(acctcode)) 00910 ast_string_field_set(tmp, accountcode, acctcode); 00911 else 00912 ast_string_field_set(tmp, accountcode, ast_default_accountcode); 00913 00914 if (!ast_strlen_zero(context)) 00915 ast_copy_string(tmp->context, context, sizeof(tmp->context)); 00916 else 00917 strcpy(tmp->context, "default"); 00918 00919 if (!ast_strlen_zero(exten)) 00920 ast_copy_string(tmp->exten, exten, sizeof(tmp->exten)); 00921 else 00922 strcpy(tmp->exten, "s"); 00923 00924 tmp->priority = 1; 00925 00926 tmp->cdr = ast_cdr_alloc(); 00927 ast_cdr_init(tmp->cdr, tmp); 00928 ast_cdr_start(tmp->cdr); 00929 00930 headp = &tmp->varshead; 00931 AST_LIST_HEAD_INIT_NOLOCK(headp); 00932 00933 ast_mutex_init(&tmp->lock_dont_use); 00934 00935 AST_LIST_HEAD_INIT_NOLOCK(&tmp->datastores); 00936 00937 ast_string_field_set(tmp, language, defaultlanguage); 00938 00939 tmp->tech = &null_tech; 00940 00941 ast_set_flag(tmp, AST_FLAG_IN_CHANNEL_LIST); 00942 00943 AST_RWLIST_WRLOCK(&channels); 00944 AST_RWLIST_INSERT_HEAD(&channels, tmp, chan_list); 00945 AST_RWLIST_UNLOCK(&channels); 00946 00947 /*\!note 00948 * and now, since the channel structure is built, and has its name, let's 00949 * call the manager event generator with this Newchannel event. This is the 00950 * proper and correct place to make this call, but you sure do have to pass 00951 * a lot of data into this func to do it here! 00952 */ 00953 if (ast_get_channel_tech(tech)) { 00954 manager_event(EVENT_FLAG_CALL, "Newchannel", 00955 "Channel: %s\r\n" 00956 "ChannelState: %d\r\n" 00957 "ChannelStateDesc: %s\r\n" 00958 "CallerIDNum: %s\r\n" 00959 "CallerIDName: %s\r\n" 00960 "AccountCode: %s\r\n" 00961 "Exten: %s\r\n" 00962 "Context: %s\r\n" 00963 "Uniqueid: %s\r\n", 00964 tmp->name, 00965 state, 00966 ast_state2str(state), 00967 S_OR(cid_num, ""), 00968 S_OR(cid_name, ""), 00969 tmp->accountcode, 00970 S_OR(exten, ""), 00971 S_OR(context, ""), 00972 tmp->uniqueid); 00973 } 00974 00975 return tmp; 00976 }
| static int __ast_queue_frame | ( | struct ast_channel * | chan, | |
| struct ast_frame * | fin, | |||
| int | head, | |||
| struct ast_frame * | after | |||
| ) | [static] |
Definition at line 997 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, errno, f, frames, ast_frame::frametype, LOG_WARNING, ast_frame::subclass, ast_channel::timer, and ast_channel::timingfd.
Referenced by __ast_read(), ast_queue_frame(), and ast_queue_frame_head().
00998 { 00999 struct ast_frame *f; 01000 struct ast_frame *cur; 01001 int blah = 1; 01002 unsigned int new_frames = 0; 01003 unsigned int new_voice_frames = 0; 01004 unsigned int queued_frames = 0; 01005 unsigned int queued_voice_frames = 0; 01006 AST_LIST_HEAD_NOLOCK(, ast_frame) frames; 01007 01008 ast_channel_lock(chan); 01009 01010 /* See if the last frame on the queue is a hangup, if so don't queue anything */ 01011 if ((cur = AST_LIST_LAST(&chan->readq)) && 01012 (cur->frametype == AST_FRAME_CONTROL) && 01013 (cur->subclass == AST_CONTROL_HANGUP)) { 01014 ast_channel_unlock(chan); 01015 return 0; 01016 } 01017 01018 /* Build copies of all the frames and count them */ 01019 AST_LIST_HEAD_INIT_NOLOCK(&frames); 01020 for (cur = fin; cur; cur = AST_LIST_NEXT(cur, frame_list)) { 01021 if (!(f = ast_frdup(cur))) { 01022 ast_frfree(AST_LIST_FIRST(&frames)); 01023 ast_channel_unlock(chan); 01024 return -1; 01025 } 01026 01027 AST_LIST_INSERT_TAIL(&frames, f, frame_list); 01028 new_frames++; 01029 if (f->frametype == AST_FRAME_VOICE) { 01030 new_voice_frames++; 01031 } 01032 } 01033 01034 /* Count how many frames exist on the queue */ 01035 AST_LIST_TRAVERSE(&chan->readq, cur, frame_list) { 01036 queued_frames++; 01037 if (cur->frametype == AST_FRAME_VOICE) { 01038 queued_voice_frames++; 01039 } 01040 } 01041 01042 if ((queued_frames + new_frames > 128 || queued_voice_frames + new_voice_frames > 96)) { 01043 int count = 0; 01044 ast_log(LOG_WARNING, "Exceptionally long %squeue length queuing to %s\n", queued_frames + new_frames > 128 ? "" : "voice ", chan->name); 01045 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->readq, cur, frame_list) { 01046 /* Save the most recent frame */ 01047 if (!AST_LIST_NEXT(cur, frame_list)) { 01048 break; 01049 } else if (cur->frametype == AST_FRAME_VOICE || cur->frametype == AST_FRAME_VIDEO || cur->frametype == AST_FRAME_NULL) { 01050 if (++count > 64) { 01051 break; 01052 } 01053 AST_LIST_REMOVE_CURRENT(frame_list); 01054 ast_frfree(cur); 01055 } 01056 } 01057 AST_LIST_TRAVERSE_SAFE_END; 01058 } 01059 01060 if (after) { 01061 AST_LIST_INSERT_LIST_AFTER(&chan->readq, &frames, after, frame_list); 01062 } else { 01063 if (head) { 01064 AST_LIST_APPEND_LIST(&frames, &chan->readq, frame_list); 01065 AST_LIST_HEAD_INIT_NOLOCK(&chan->readq); 01066 } 01067 AST_LIST_APPEND_LIST(&chan->readq, &frames, frame_list); 01068 } 01069 01070 if (chan->alertpipe[1] > -1) { 01071 if (write(chan->alertpipe[1], &blah, new_frames * sizeof(blah)) != (new_frames * sizeof(blah))) { 01072 ast_log(LOG_WARNING, "Unable to write to alert pipe on %s (qlen = %d): %s!\n", 01073 chan->name, queued_frames, strerror(errno)); 01074 } 01075 } else if (chan->timingfd > -1) { 01076 ast_timer_enable_continuous(chan->timer); 01077 } else if (ast_test_flag(chan, AST_FLAG_BLOCKING)) { 01078 pthread_kill(chan->blocker, SIGURG); 01079 } 01080 01081 ast_channel_unlock(chan); 01082 01083 return 0; 01084 }
| static struct ast_frame* __ast_read | ( | struct ast_channel * | chan, | |
| int | dropaudio | |||
| ) | [static, read] |
Definition at line 2699 of file channel.c.
References __ast_queue_frame(), ast_channel::_softhangup, ast_channel::_state, ast_channel::alertpipe, ast_audiohook_detach_list(), AST_AUDIOHOOK_DIRECTION_READ, ast_audiohook_write_list(), ast_audiohook_write_list_empty(), 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(), cause, ast_frame::data, 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_frame::frametype, ast_generator::generate, ast_channel::generator, ast_channel::generatordata, ast_channel::hangupcause, ast_channel::insmpl, ast_frame::len, LOG_DTMF, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_channel::masq, ast_channel::monitor, ast_channel::music_state, ast_channel::nativeformats, ast_channel::outsmpl, queue_dtmf_readq(), ast_channel_tech::read, ast_channel_monitor::read_stream, ast_channel::readtrans, ast_frame::samples, SEEK_FORCECUR, send_dtmf_event(), should_skip_dtmf(), ast_channel_monitor::state, ast_frame::subclass, ast_channel::tech, ast_channel::timer, ast_channel::timingdata, ast_channel::timingfd, ast_channel::timingfunc, and ast_frame::uint32.
Referenced by ast_read(), and ast_read_noaudio().
02700 { 02701 struct ast_frame *f = NULL; /* the return value */ 02702 int blah; 02703 int prestate; 02704 int count = 0, cause = 0; 02705 02706 /* this function is very long so make sure there is only one return 02707 * point at the end (there are only two exceptions to this). 02708 */ 02709 while(ast_channel_trylock(chan)) { 02710 if(count++ > 10) 02711 /*cannot goto done since the channel is not locked*/ 02712 return &ast_null_frame; 02713 usleep(1); 02714 } 02715 02716 if (chan->masq) { 02717 if (ast_do_masquerade(chan)) 02718 ast_log(LOG_WARNING, "Failed to perform masquerade\n"); 02719 else 02720 f = &ast_null_frame; 02721 goto done; 02722 } 02723 02724 /* Stop if we're a zombie or need a soft hangup */ 02725 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 02726 if (chan->generator) 02727 ast_deactivate_generator(chan); 02728 goto done; 02729 } 02730 02731 #ifdef AST_DEVMODE 02732 /* 02733 * The ast_waitfor() code records which of the channel's file descriptors reported that 02734 * data is available. In theory, ast_read() should only be called after ast_waitfor() 02735 * reports that a channel has data available for reading. However, there still may be 02736 * some edge cases throughout the code where ast_read() is called improperly. This can 02737 * potentially cause problems, so if this is a developer build, make a lot of noise if 02738 * this happens so that it can be addressed. 02739 */ 02740 if (chan->fdno == -1) { 02741 ast_log(LOG_ERROR, "ast_read() called with no recorded file descriptor.\n"); 02742 } 02743 #endif 02744 02745 prestate = chan->_state; 02746 02747 /* Read and ignore anything on the alertpipe, but read only 02748 one sizeof(blah) per frame that we send from it */ 02749 if (chan->alertpipe[0] > -1) { 02750 int flags = fcntl(chan->alertpipe[0], F_GETFL); 02751 /* For some odd reason, the alertpipe occasionally loses nonblocking status, 02752 * which immediately causes a deadlock scenario. Detect and prevent this. */ 02753 if ((flags & O_NONBLOCK) == 0) { 02754 ast_log(LOG_ERROR, "Alertpipe on channel %s lost O_NONBLOCK?!!\n", chan->name); 02755 if (fcntl(chan->alertpipe[0], F_SETFL, flags | O_NONBLOCK) < 0) { 02756 ast_log(LOG_WARNING, "Unable to set alertpipe nonblocking! (%d: %s)\n", errno, strerror(errno)); 02757 f = &ast_null_frame; 02758 goto done; 02759 } 02760 } 02761 if (read(chan->alertpipe[0], &blah, sizeof(blah)) < 0) { 02762 if (errno != EINTR && errno != EAGAIN) 02763 ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno)); 02764 } 02765 } 02766 02767 if (chan->timingfd > -1 && chan->fdno == AST_TIMING_FD) { 02768 enum ast_timer_event res; 02769 02770 ast_clear_flag(chan, AST_FLAG_EXCEPTION); 02771 02772 res = ast_timer_get_event(chan->timer); 02773 02774 switch (res) { 02775 case AST_TIMING_EVENT_EXPIRED: 02776 ast_timer_ack(chan->timer, 1); 02777 02778 if (chan->timingfunc) { 02779 /* save a copy of func/data before unlocking the channel */ 02780 int (*func)(const void *) = chan->timingfunc; 02781 void *data = chan->timingdata; 02782 chan->fdno = -1; 02783 ast_channel_unlock(chan); 02784 func(data); 02785 } else { 02786 ast_timer_set_rate(chan->timer, 0); 02787 chan->fdno = -1; 02788 ast_channel_unlock(chan); 02789 } 02790 02791 /* cannot 'goto done' because the channel is already unlocked */ 02792 return &ast_null_frame; 02793 02794 case AST_TIMING_EVENT_CONTINUOUS: 02795 if (AST_LIST_EMPTY(&chan->readq) || 02796 !AST_LIST_NEXT(AST_LIST_FIRST(&chan->readq), frame_list)) { 02797 ast_timer_disable_continuous(chan->timer); 02798 } 02799 break; 02800 } 02801 02802 } else if (chan->fds[AST_GENERATOR_FD] > -1 && chan->fdno == AST_GENERATOR_FD) { 02803 /* if the AST_GENERATOR_FD is set, call the generator with args 02804 * set to -1 so it can do whatever it needs to. 02805 */ 02806 void *tmp = chan->generatordata; 02807 chan->generatordata = NULL; /* reset to let ast_write get through */ 02808 chan->generator->generate(chan, tmp, -1, -1); 02809 chan->generatordata = tmp; 02810 f = &ast_null_frame; 02811 chan->fdno = -1; 02812 goto done; 02813 } 02814 02815 /* Check for pending read queue */ 02816 if (!AST_LIST_EMPTY(&chan->readq)) { 02817 int skip_dtmf = should_skip_dtmf(chan); 02818 02819 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->readq, f, frame_list) { 02820 /* We have to be picky about which frame we pull off of the readq because 02821 * there are cases where we want to leave DTMF frames on the queue until 02822 * some later time. */ 02823 02824 if ( (f->frametype == AST_FRAME_DTMF_BEGIN || f->frametype == AST_FRAME_DTMF_END) && skip_dtmf) { 02825 continue; 02826 } 02827 02828 AST_LIST_REMOVE_CURRENT(frame_list); 02829 break; 02830 } 02831 AST_LIST_TRAVERSE_SAFE_END; 02832 02833 if (!f) { 02834 /* There were no acceptable frames on the readq. */ 02835 f = &ast_null_frame; 02836 if (chan->alertpipe[0] > -1) { 02837 int poke = 0; 02838 /* Restore the state of the alertpipe since we aren't ready for any 02839 * of the frames in the readq. */ 02840 if (write(chan->alertpipe[1], &poke, sizeof(poke)) != sizeof(poke)) { 02841 ast_log(LOG_ERROR, "Failed to write to alertpipe: %s\n", strerror(errno)); 02842 } 02843 } 02844 } 02845 02846 /* Interpret hangup and return NULL */ 02847 /* XXX why not the same for frames from the channel ? */ 02848 if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) { 02849 cause = f->data.uint32; 02850 ast_frfree(f); 02851 f = NULL; 02852 } 02853 } else { 02854 chan->blocker = pthread_self(); 02855 if (ast_test_flag(chan, AST_FLAG_EXCEPTION)) { 02856 if (chan->tech->exception) 02857 f = chan->tech->exception(chan); 02858 else { 02859 ast_log(LOG_WARNING, "Exception flag set on '%s', but no exception handler\n", chan->name); 02860 f = &ast_null_frame; 02861 } 02862 /* Clear the exception flag */ 02863 ast_clear_flag(chan, AST_FLAG_EXCEPTION); 02864 } else if (chan->tech->read) 02865 f = chan->tech->read(chan); 02866 else 02867 ast_log(LOG_WARNING, "No read routine on channel %s\n", chan->name); 02868 } 02869 02870 /* 02871 * Reset the recorded file descriptor that triggered this read so that we can 02872 * easily detect when ast_read() is called without properly using ast_waitfor(). 02873 */ 02874 chan->fdno = -1; 02875 02876 if (f) { 02877 struct ast_frame *readq_tail = AST_LIST_LAST(&chan->readq); 02878 02879 /* if the channel driver returned more than one frame, stuff the excess 02880 into the readq for the next ast_read call 02881 */ 02882 if (AST_LIST_NEXT(f, frame_list)) { 02883 ast_queue_frame(chan, AST_LIST_NEXT(f, frame_list)); 02884 ast_frfree(AST_LIST_NEXT(f, frame_list)); 02885 AST_LIST_NEXT(f, frame_list) = NULL; 02886 } 02887 02888 switch (f->frametype) { 02889 case AST_FRAME_CONTROL: 02890 if (f->subclass == AST_CONTROL_ANSWER) { 02891 if (!ast_test_flag(chan, AST_FLAG_OUTGOING)) { 02892 ast_debug(1, "Ignoring answer on an inbound call!\n"); 02893 ast_frfree(f); 02894 f = &ast_null_frame; 02895 } else if (prestate == AST_STATE_UP) { 02896 ast_debug(1, "Dropping duplicate answer!\n"); 02897 ast_frfree(f); 02898 f = &ast_null_frame; 02899 } else { 02900 /* Answer the CDR */ 02901 ast_setstate(chan, AST_STATE_UP); 02902 /* removed a call to ast_cdr_answer(chan->cdr) from here. */ 02903 } 02904 } 02905 break; 02906 case AST_FRAME_DTMF_END: 02907 send_dtmf_event(chan, "Received", f->subclass, "No", "Yes"); 02908 ast_log(LOG_DTMF, "DTMF end '%c' received on %s, duration %ld ms\n", f->subclass, chan->name, f->len); 02909 /* Queue it up if DTMF is deferred, or if DTMF emulation is forced. */ 02910 if (ast_test_flag(chan, AST_FLAG_DEFER_DTMF) || ast_test_flag(chan, AST_FLAG_EMULATE_DTMF)) { 02911 queue_dtmf_readq(chan, f); 02912 ast_frfree(f); 02913 f = &ast_null_frame; 02914 } else if (!ast_test_flag(chan, AST_FLAG_IN_DTMF | AST_FLAG_END_DTMF_ONLY)) { 02915 if (!ast_tvzero(chan->dtmf_tv) && 02916 ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) { 02917 /* If it hasn't been long enough, defer this digit */ 02918 queue_dtmf_readq(chan, f); 02919 ast_frfree(f); 02920 f = &ast_null_frame; 02921 } else { 02922 /* There was no begin, turn this into a begin and send the end later */ 02923 f->frametype = AST_FRAME_DTMF_BEGIN; 02924 ast_set_flag(chan, AST_FLAG_EMULATE_DTMF); 02925 chan->emulate_dtmf_digit = f->subclass; 02926 chan->dtmf_tv = ast_tvnow(); 02927 if (f->len) { 02928 if (f->len > AST_MIN_DTMF_DURATION) 02929 chan->emulate_dtmf_duration = f->len; 02930 else 02931 chan->emulate_dtmf_duration = AST_MIN_DTMF_DURATION; 02932 } else 02933 chan->emulate_dtmf_duration = AST_DEFAULT_EMULATE_DTMF_DURATION; 02934 ast_log(LOG_DTMF, "DTMF begin emulation of '%c' with duration %u queued on %s\n", f->subclass, chan->emulate_dtmf_duration, chan->name); 02935 } 02936 if (chan->audiohooks) { 02937 struct ast_frame *old_frame = f; 02938 /*! 02939 * \todo XXX It is possible to write a digit to the audiohook twice 02940 * if the digit was originally read while the channel was in autoservice. */ 02941 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 02942 if (old_frame != f) 02943 ast_frfree(old_frame); 02944 } 02945 } else { 02946 struct timeval now = ast_tvnow(); 02947 if (ast_test_flag(chan, AST_FLAG_IN_DTMF)) { 02948 ast_log(LOG_DTMF, "DTMF end accepted with begin '%c' on %s\n", f->subclass, chan->name); 02949 ast_clear_flag(chan, AST_FLAG_IN_DTMF); 02950 if (!f->len) 02951 f->len = ast_tvdiff_ms(now, chan->dtmf_tv); 02952 02953 /* detect tones that were received on 02954 * the wire with durations shorter than 02955 * AST_MIN_DTMF_DURATION and set f->len 02956 * to the actual duration of the DTMF 02957 * frames on the wire. This will cause 02958 * dtmf emulation to be triggered later 02959 * on. 02960 */ 02961 if (ast_tvdiff_ms(now, chan->dtmf_tv) < AST_MIN_DTMF_DURATION) { 02962 f->len = ast_tvdiff_ms(now, chan->dtmf_tv); 02963 ast_log(LOG_DTMF, "DTMF end '%c' detected to have actual duration %ld on the wire, emulation will be triggered on %s\n", f->subclass, f->len, chan->name); 02964 } 02965 } else if (!f->len) { 02966 ast_log(LOG_DTMF, "DTMF end accepted without begin '%c' on %s\n", f->subclass, chan->name); 02967 f->len = AST_MIN_DTMF_DURATION; 02968 } 02969 if (f->len < AST_MIN_DTMF_DURATION && !ast_test_flag(chan, AST_FLAG_END_DTMF_ONLY)) { 02970 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); 02971 ast_set_flag(chan, AST_FLAG_EMULATE_DTMF); 02972 chan->emulate_dtmf_digit = f->subclass; 02973 chan->emulate_dtmf_duration = AST_MIN_DTMF_DURATION - f->len; 02974 ast_frfree(f); 02975 f = &ast_null_frame; 02976 } else { 02977 ast_log(LOG_DTMF, "DTMF end passthrough '%c' on %s\n", f->subclass, chan->name); 02978 if (f->len < AST_MIN_DTMF_DURATION) { 02979 f->len = AST_MIN_DTMF_DURATION; 02980 } 02981 chan->dtmf_tv = now; 02982 } 02983 if (chan->audiohooks) { 02984 struct ast_frame *old_frame = f; 02985 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 02986 if (old_frame != f) 02987 ast_frfree(old_frame); 02988 } 02989 } 02990 break; 02991 case AST_FRAME_DTMF_BEGIN: 02992 send_dtmf_event(chan, "Received", f->subclass, "Yes", "No"); 02993 ast_log(LOG_DTMF, "DTMF begin '%c' received on %s\n", f->subclass, chan->name); 02994 if ( ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_END_DTMF_ONLY | AST_FLAG_EMULATE_DTMF) || 02995 (!ast_tvzero(chan->dtmf_tv) && 02996 ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) ) { 02997 ast_log(LOG_DTMF, "DTMF begin ignored '%c' on %s\n", f->subclass, chan->name); 02998 ast_frfree(f); 02999 f = &ast_null_frame; 03000 } else { 03001 ast_set_flag(chan, AST_FLAG_IN_DTMF); 03002 chan->dtmf_tv = ast_tvnow(); 03003 ast_log(LOG_DTMF, "DTMF begin passthrough '%c' on %s\n", f->subclass, chan->name); 03004 } 03005 break; 03006 case AST_FRAME_NULL: 03007 /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration 03008 * is reached , because we want to make sure we pass at least one 03009 * voice frame through before starting the next digit, to ensure a gap 03010 * between DTMF digits. */ 03011 if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF)) { 03012 struct timeval now = ast_tvnow(); 03013 if (!chan->emulate_dtmf_duration) { 03014 ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF); 03015 chan->emulate_dtmf_digit = 0; 03016 } else if (ast_tvdiff_ms(now, chan->dtmf_tv) >= chan->emulate_dtmf_duration) { 03017 chan->emulate_dtmf_duration = 0; 03018 ast_frfree(f); 03019 f = &chan->dtmff; 03020 f->frametype = AST_FRAME_DTMF_END; 03021 f->subclass = chan->emulate_dtmf_digit; 03022 f->len = ast_tvdiff_ms(now, chan->dtmf_tv); 03023 chan->dtmf_tv = now; 03024 ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF); 03025 chan->emulate_dtmf_digit = 0; 03026 ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass, chan->name); 03027 if (chan->audiohooks) { 03028 struct ast_frame *old_frame = f; 03029 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 03030 if (old_frame != f) { 03031 ast_frfree(old_frame); 03032 } 03033 } 03034 } 03035 } 03036 break; 03037 case AST_FRAME_VOICE: 03038 /* The EMULATE_DTMF flag must be cleared here as opposed to when the duration 03039 * is reached , because we want to make sure we pass at least one 03040 * voice frame through before starting the next digit, to ensure a gap 03041 * between DTMF digits. */ 03042 if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF) && !chan->emulate_dtmf_duration) { 03043 ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF); 03044 chan->emulate_dtmf_digit = 0; 03045 } 03046 03047 if (dropaudio || ast_test_flag(chan, AST_FLAG_IN_DTMF)) { 03048 if (dropaudio) 03049 ast_read_generator_actions(chan, f); 03050 ast_frfree(f); 03051 f = &ast_null_frame; 03052 } 03053 03054 if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF) && !ast_test_flag(chan, AST_FLAG_IN_DTMF)) { 03055 struct timeval now = ast_tvnow(); 03056 if (ast_tvdiff_ms(now, chan->dtmf_tv) >= chan->emulate_dtmf_duration) { 03057 chan->emulate_dtmf_duration = 0; 03058 ast_frfree(f); 03059 f = &chan->dtmff; 03060 f->frametype = AST_FRAME_DTMF_END; 03061 f->subclass = chan->emulate_dtmf_digit; 03062 f->len = ast_tvdiff_ms(now, chan->dtmf_tv); 03063 chan->dtmf_tv = now; 03064 if (chan->audiohooks) { 03065 struct ast_frame *old_frame = f; 03066 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 03067 if (old_frame != f) 03068 ast_frfree(old_frame); 03069 } 03070 ast_log(LOG_DTMF, "DTMF end emulation of '%c' queued on %s\n", f->subclass, chan->name); 03071 } else { 03072 /* Drop voice frames while we're still in the middle of the digit */ 03073 ast_frfree(f); 03074 f = &ast_null_frame; 03075 } 03076 } else if ((f->frametype == AST_FRAME_VOICE) && !(f->subclass & chan->nativeformats)) { 03077 /* This frame is not one of the current native formats -- drop it on the floor */ 03078 char to[200]; 03079 ast_log(LOG_NOTICE, "Dropping incompatible voice frame on %s of format %s since our native format has changed to %s\n", 03080 chan->name, ast_getformatname(f->subclass), ast_getformatname_multiple(to, sizeof(to), chan->nativeformats)); 03081 ast_frfree(f); 03082 f = &ast_null_frame; 03083 } else if ((f->frametype == AST_FRAME_VOICE)) { 03084 /* Send frame to audiohooks if present */ 03085 if (chan->audiohooks) { 03086 struct ast_frame *old_frame = f; 03087 f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f); 03088 if (old_frame != f) 03089 ast_frfree(old_frame); 03090 } 03091 if (chan->monitor && chan->monitor->read_stream ) { 03092 /* XXX what does this do ? */ 03093 #ifndef MONITOR_CONSTANT_DELAY 03094 int jump = chan->outsmpl - chan->insmpl - 4 * f->samples; 03095 if (jump >= 0) { 03096 jump = calc_monitor_jump((chan->outsmpl - chan->insmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format)); 03097 if (ast_seekstream(chan->monitor->read_stream, jump, SEEK_FORCECUR) == -1) 03098 ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n"); 03099 chan->insmpl += (chan->outsmpl - chan->insmpl) + f->samples; 03100 } else 03101 chan->insmpl+= f->samples; 03102 #else 03103 int jump = calc_monitor_jump((chan->outsmpl - chan->insmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format)); 03104 if (jump - MONITOR_DELAY >= 0) { 03105 if (ast_seekstream(chan->monitor->read_stream, jump - f->samples, SEEK_FORCECUR) == -1) 03106 ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n"); 03107 chan->insmpl += chan->outsmpl - chan->insmpl; 03108 } else 03109 chan->insmpl += f->samples; 03110 #endif 03111 if (chan->monitor->state == AST_MONITOR_RUNNING) { 03112 if (ast_writestream(chan->monitor->read_stream, f) < 0) 03113 ast_log(LOG_WARNING, "Failed to write data to channel monitor read stream\n"); 03114 } 03115 } 03116 03117 if (chan->readtrans && (f = ast_translate(chan->readtrans, f, 1)) == NULL) { 03118 f = &ast_null_frame; 03119 } 03120 03121 /* it is possible for the translation process on chan->readtrans to have 03122 produced multiple frames from the single input frame we passed it; if 03123 this happens, queue the additional frames *before* the frames we may 03124 have queued earlier. if the readq was empty, put them at the head of 03125 the queue, and if it was not, put them just after the frame that was 03126 at the end of the queue. 03127 */ 03128 if (AST_LIST_NEXT(f, frame_list)) { 03129 if (!readq_tail) { 03130 ast_queue_frame_head(chan, AST_LIST_NEXT(f, frame_list)); 03131 } else { 03132 __ast_queue_frame(chan, AST_LIST_NEXT(f, frame_list), 0, readq_tail); 03133 } 03134 ast_frfree(AST_LIST_NEXT(f, frame_list)); 03135 AST_LIST_NEXT(f, frame_list) = NULL; 03136 } 03137 03138 /* Run generator sitting on the line if timing device not available 03139 * and synchronous generation of outgoing frames is necessary */ 03140 ast_read_generator_actions(chan, f); 03141 } 03142 default: 03143 /* Just pass it on! */ 03144 break; 03145 } 03146 } else { 03147 /* Make sure we always return NULL in the future */ 03148 chan->_softhangup |= AST_SOFTHANGUP_DEV; 03149 if (cause) 03150 chan->hangupcause = cause; 03151 if (chan->generator) 03152 ast_deactivate_generator(chan); 03153 /* We no longer End the CDR here */ 03154 } 03155 03156 /* High bit prints debugging */ 03157 if (chan->fin & DEBUGCHAN_FLAG) 03158 ast_frame_dump(chan->name, f, "<<"); 03159 chan->fin = FRAMECOUNT_INC(chan->fin); 03160 03161 done: 03162 if (chan->music_state && chan->generator && chan->generator->digit && f && f->frametype == AST_FRAME_DTMF_END) 03163 chan->generator->digit(chan, f->subclass); 03164 03165 if (chan->audiohooks && ast_audiohook_write_list_empty(chan->audiohooks)) { 03166 /* The list gets recreated if audiohooks are added again later */ 03167 ast_audiohook_detach_list(chan->audiohooks); 03168 chan->audiohooks = NULL; 03169 } 03170 ast_channel_unlock(chan); 03171 return f; 03172 }
| 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 | |||
| ) | [read] |
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 4049 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(), cause, ast_channel::cdr, outgoing_helper::cid_name, outgoing_helper::cid_num, ast_channel::context, outgoing_helper::context, ast_channel::exten, outgoing_helper::exten, f, ast_frame::frametype, handle_cause(), ast_channel::hangupcause, LOG_NOTICE, outgoing_helper::parent_channel, ast_channel::priority, outgoing_helper::priority, ast_frame::subclass, and outgoing_helper::vars.
Referenced by ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_request_and_dial(), and parkandannounce_exec().
04050 { 04051 int dummy_outstate; 04052 int cause = 0; 04053 struct ast_channel *chan; 04054 int res = 0; 04055 int last_subclass = 0; 04056 04057 if (outstate) 04058 *outstate = 0; 04059 else 04060 outstate = &dummy_outstate; /* make outstate always a valid pointer */ 04061 04062 chan = ast_request(type, format, data, &cause); 04063 if (!chan) { 04064 ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data); 04065 handle_cause(cause, outstate); 04066 return NULL; 04067 } 04068 04069 if (oh) { 04070 if (oh->vars) 04071 ast_set_variables(chan, oh->vars); 04072 /* XXX why is this necessary, for the parent_channel perhaps ? */ 04073 if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) 04074 ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num); 04075 if (oh->parent_channel) { 04076 ast_channel_inherit_variables(oh->parent_channel, chan); 04077 ast_channel_datastore_inherit(oh->parent_channel, chan); 04078 } 04079 if (oh->account) 04080 ast_cdr_setaccount(chan, oh->account); 04081 } 04082 ast_set_callerid(chan, cid_num, cid_name, cid_num); 04083 ast_set_flag(chan->cdr, AST_CDR_FLAG_ORIGINATED); 04084 04085 if (ast_call(chan, data, 0)) { /* ast_call failed... */ 04086 ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data); 04087 } else { 04088 res = 1; /* mark success in case chan->_state is already AST_STATE_UP */ 04089 while (timeout && chan->_state != AST_STATE_UP) { 04090 struct ast_frame *f; 04091 res = ast_waitfor(chan, timeout); 04092 if (res == 0) { /* timeout, treat it like ringing */ 04093 *outstate = AST_CONTROL_RINGING; 04094 break; 04095 } 04096 if (res < 0) /* error or done */ 04097 break; 04098 if (timeout > -1) 04099 timeout = res; 04100 if (!ast_strlen_zero(chan->call_forward)) { 04101 if (!(chan = ast_call_forward(NULL, chan, &timeout, format, oh, outstate))) { 04102 return NULL; 04103 } 04104 continue; 04105 } 04106 04107 f = ast_read(chan); 04108 if (!f) { 04109 *outstate = AST_CONTROL_HANGUP; 04110 res = 0; 04111 break; 04112 } 04113 if (f->frametype == AST_FRAME_CONTROL) { 04114 switch (f->subclass) { 04115 case AST_CONTROL_RINGING: /* record but keep going */ 04116 *outstate = f->subclass; 04117 break; 04118 04119 case AST_CONTROL_BUSY: 04120 ast_cdr_busy(chan->cdr); 04121 *outstate = f->subclass; 04122 timeout = 0; 04123 break; 04124 04125 case AST_CONTROL_CONGESTION: 04126 ast_cdr_failed(chan->cdr); 04127 *outstate = f->subclass; 04128 timeout = 0; 04129 break; 04130 04131 case AST_CONTROL_ANSWER: 04132 ast_cdr_answer(chan->cdr); 04133 *outstate = f->subclass; 04134 timeout = 0; /* trick to force exit from the while() */ 04135 break; 04136 04137 /* Ignore these */ 04138 case AST_CONTROL_PROGRESS: 04139 case AST_CONTROL_PROCEEDING: 04140 case AST_CONTROL_HOLD: 04141 case AST_CONTROL_UNHOLD: 04142 case AST_CONTROL_VIDUPDATE: 04143 case AST_CONTROL_SRCUPDATE: 04144 case AST_CONTROL_SRCCHANGE: 04145 case -1: /* Ignore -- just stopping indications */ 04146 break; 04147 04148 default: 04149 ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass); 04150 } 04151 last_subclass = f->subclass; 04152 } 04153 ast_frfree(f); 04154 } 04155 } 04156 04157 /* Final fixups */ 04158 if (oh) { 04159 if (!ast_strlen_zero(oh->context)) 04160 ast_copy_string(chan->context, oh->context, sizeof(chan->context)); 04161 if (!ast_strlen_zero(oh->exten)) 04162 ast_copy_string(chan->exten, oh->exten, sizeof(chan->exten)); 04163 if (oh->priority) 04164 chan->priority = oh->priority; 04165 } 04166 if (chan->_state == AST_STATE_UP) 04167 *outstate = AST_CONTROL_ANSWER; 04168 04169 if (res <= 0) { 04170 if ( AST_CONTROL_RINGING == last_subclass ) 04171 chan->hangupcause = AST_CAUSE_NO_ANSWER; 04172 if (!chan->cdr && (chan->cdr = ast_cdr_alloc())) 04173 ast_cdr_init(chan->cdr, chan); 04174 if (chan->cdr) { 04175 char tmp[256]; 04176 snprintf(tmp, sizeof(tmp), "%s/%s", type, (char *)data); 04177 ast_cdr_setapp(chan->cdr,"Dial",tmp); 04178 ast_cdr_update(chan); 04179 ast_cdr_start(chan->cdr); 04180 ast_cdr_end(chan->cdr); 04181 /* If the cause wasn't handled properly */ 04182 if (ast_cdr_disposition(chan->cdr,chan->hangupcause)) 04183 ast_cdr_failed(chan->cdr); 04184 } 04185 ast_hangup(chan); 04186 chan = NULL; 04187 } 04188 return chan; 04189 }
| static void __init_state2str_threadbuf | ( | void | ) | [static] |
| static void adjust_frame_for_plc | ( | struct ast_channel * | chan, | |
| struct ast_frame * | frame, | |||
| struct ast_datastore * | datastore | |||
| ) | [static] |
Definition at line 3518 of file channel.c.
References ast_calloc, ast_channel_datastore_remove(), ast_datastore_free(), ast_free, AST_FRIENDLY_OFFSET, ast_frame::data, ast_datastore::data, ast_frame::datalen, plc_ds::num_samples, ast_frame::offset, plc_fillin(), plc_rx(), plc_ds::plc_state, ast_frame::ptr, ast_frame::samples, and plc_ds::samples_buf.
Referenced by apply_plc().
03519 { 03520 int num_new_samples = frame->samples; 03521 struct plc_ds *plc = datastore->data; 03522 03523 /* As a general note, let me explain the somewhat odd calculations used when taking 03524 * the frame offset into account here. According to documentation in frame.h, the frame's 03525 * offset field indicates the number of bytes that the audio is offset. The plc->samples_buf 03526 * is not an array of bytes, but rather an array of 16-bit integers since it holds SLIN 03527 * samples. So I had two choices to make here with the offset. 03528 * 03529 * 1. Make the offset AST_FRIENDLY_OFFSET bytes. The main downside for this is that 03530 * I can't just add AST_FRIENDLY_OFFSET to the plc->samples_buf and have the pointer 03531 * arithmetic come out right. I would have to do some odd casting or division for this to 03532 * work as I wanted. 03533 * 2. Make the offset AST_FRIENDLY_OFFSET * 2 bytes. This allows the pointer arithmetic 03534 * to work out better with the plc->samples_buf. The downside here is that the buffer's 03535 * allocation contains an extra 64 bytes of unused space. 03536 * 03537 * I decided to go with option 2. This is why in the calloc statement and the statement that 03538 * sets the frame's offset, AST_FRIENDLY_OFFSET is multiplied by 2. 03539 */ 03540 03541 /* If this audio frame has no samples to fill in, ignore it */ 03542 if (!num_new_samples) { 03543 return; 03544 } 03545 03546 /* First, we need to be sure that our buffer is large enough to accomodate 03547 * the samples we need to fill in. This will likely only occur on the first 03548 * frame we write. 03549 */ 03550 if (plc->num_samples < num_new_samples) { 03551 ast_free(plc->samples_buf); 03552 plc->samples_buf = ast_calloc(1, (num_new_samples * sizeof(*plc->samples_buf)) + (AST_FRIENDLY_OFFSET * 2)); 03553 if (!plc->samples_buf) { 03554 ast_channel_datastore_remove(chan, datastore); 03555 ast_datastore_free(datastore); 03556 return; 03557 } 03558 plc->num_samples = num_new_samples; 03559 } 03560 03561 if (frame->datalen == 0) { 03562 plc_fillin(&plc->plc_state, plc->samples_buf + AST_FRIENDLY_OFFSET, frame->samples); 03563 frame->data.ptr = plc->samples_buf + AST_FRIENDLY_OFFSET; 03564 frame->datalen = num_new_samples * 2; 03565 frame->offset = AST_FRIENDLY_OFFSET * 2; 03566 } else { 03567 plc_rx(&plc->plc_state, frame->data.ptr, frame->samples); 03568 } 03569 }
| static void apply_plc | ( | struct ast_channel * | chan, | |
| struct ast_frame * | frame | |||
| ) | [static] |
Definition at line 3571 of file channel.c.
References adjust_frame_for_plc(), ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_datastore_alloc, ast_datastore_free(), ast_datastore::data, and plc_ds_info.
Referenced by ast_write().
03572 { 03573 struct ast_datastore *datastore; 03574 struct plc_ds *plc; 03575 03576 datastore = ast_channel_datastore_find(chan, &plc_ds_info, NULL); 03577 if (datastore) { 03578 plc = datastore->data; 03579 adjust_frame_for_plc(chan, frame, datastore); 03580 return; 03581 } 03582 03583 datastore = ast_datastore_alloc(&plc_ds_info, NULL); 03584 if (!datastore) { 03585 return; 03586 } 03587 plc = ast_calloc(1, sizeof(*plc)); 03588 if (!plc) { 03589 ast_datastore_free(datastore); 03590 return; 03591 } 03592 datastore->data = plc; 03593 ast_channel_datastore_add(chan, datastore); 03594 adjust_frame_for_plc(chan, frame, datastore); 03595 }
| int ast_activate_generator | ( | struct ast_channel * | chan, | |
| struct ast_generator * | gen, | |||
| void * | params | |||
| ) |
Activate a given generator
Definition at line 2061 of file channel.c.
References ast_generator::alloc, ast_channel_lock, ast_channel_unlock, ast_prod(), ast_settimeout(), 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(), local_ast_moh_start(), old_milliwatt_exec(), and transmit_audio().
02062 { 02063 int res = 0; 02064 02065 ast_channel_lock(chan); 02066 if (chan->generatordata) { 02067 if (chan->generator && chan->generator->release) 02068 chan->generator->release(chan, chan->generatordata); 02069 chan->generatordata = NULL; 02070 } 02071 if (gen->alloc && !(chan->generatordata = gen->alloc(chan, params))) { 02072 res = -1; 02073 } 02074 if (!res) { 02075 ast_settimeout(chan, 50, generator_force, chan); 02076 chan->generator = gen; 02077 } 02078 ast_channel_unlock(chan); 02079 02080 ast_prod(chan); 02081 02082 return res; 02083 }
| int ast_active_channels | ( | void | ) |
returns number of active/allocated channels
Returns number of active/allocated channels
Definition at line 497 of file channel.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, and AST_RWLIST_UNLOCK.
Referenced by action_corestatus(), ast_var_channels(), ast_var_channels_table(), dahdi_restart(), handle_show_settings(), and quit_handler().
00498 { 00499 struct ast_channel *c; 00500 int cnt = 0; 00501 AST_RWLIST_RDLOCK(&channels); 00502 AST_RWLIST_TRAVERSE(&channels, c, chan_list) 00503 cnt++; 00504 AST_RWLIST_UNLOCK(&channels); 00505 return cnt; 00506 }
| int ast_answer | ( | struct ast_channel * | chan | ) |
Answer a channel.
| chan | channel to answer |
This function answers a channel and handles all necessary call setup functions.
| 0 | on success | |
| non-zero | on failure |
Definition at line 2011 of file channel.c.
References __ast_answer().
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(), record_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().
02012 { 02013 return __ast_answer(chan, 0, 1); 02014 }
| 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 483 of file channel.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_softhangup(), and AST_SOFTHANGUP_SHUTDOWN.
Referenced by quit_handler().
00484 { 00485 struct ast_channel *c; 00486 shutting_down = 1; 00487 if (hangup) { 00488 AST_RWLIST_RDLOCK(&channels); 00489 AST_RWLIST_TRAVERSE(&channels, c, chan_list) { 00490 ast_softhangup(c, AST_SOFTHANGUP_SHUTDOWN); 00491 } 00492 AST_RWLIST_UNLOCK(&channels); 00493 } 00494 }
| 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 711 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_SIREN14, AST_FORMAT_SIREN7, 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(), bridge_make_compatible(), 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().
00712 { 00713 /* This just our opinion, expressed in code. We are asked to choose 00714 the best codec to use, given no information */ 00715 int x; 00716 static const int prefs[] = 00717 { 00718 /*! Okay, ulaw is used by all telephony equipment, so start with it */ 00719 AST_FORMAT_ULAW, 00720 /*! Unless of course, you're a silly European, so then prefer ALAW */ 00721 AST_FORMAT_ALAW, 00722 AST_FORMAT_SIREN14, 00723 AST_FORMAT_SIREN7, 00724 /*! G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority */ 00725 AST_FORMAT_G722, 00726 /*! Okay, well, signed linear is easy to translate into other stuff */ 00727 AST_FORMAT_SLINEAR16, 00728 AST_FORMAT_SLINEAR, 00729 /*! G.726 is standard ADPCM, in RFC3551 packing order */ 00730 AST_FORMAT_G726, 00731 /*! G.726 is standard ADPCM, in AAL2 packing order */ 00732 AST_FORMAT_G726_AAL2, 00733 /*! ADPCM has great sound quality and is still pretty easy to translate */ 00734 AST_FORMAT_ADPCM, 00735 /*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to 00736 translate and sounds pretty good */ 00737 AST_FORMAT_GSM, 00738 /*! iLBC is not too bad */ 00739 AST_FORMAT_ILBC, 00740 /*! Speex is free, but computationally more expensive than GSM */ 00741 AST_FORMAT_SPEEX, 00742 /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough 00743 to use it */ 00744 AST_FORMAT_LPC10, 00745 /*! G.729a is faster than 723 and slightly less expensive */ 00746 AST_FORMAT_G729A, 00747 /*! Down to G.723.1 which is proprietary but at least designed for voice */ 00748 AST_FORMAT_G723_1, 00749 }; 00750 00751 /* Strip out video */ 00752 fmts &= AST_FORMAT_AUDIO_MASK; 00753 00754 /* Find the first preferred codec in the format given */ 00755 for (x = 0; x < ARRAY_LEN(prefs); x++) { 00756 if (fmts & prefs[x]) 00757 return prefs[x]; 00758 } 00759 00760 ast_log(LOG_WARNING, "Don't know any of 0x%x formats\n", fmts); 00761 00762 return 0; 00763 }
| struct ast_channel* ast_bridged_channel | ( | struct ast_channel * | chan | ) | [read] |
Find bridged channel.
| chan | Current channel |
Definition at line 4956 of file channel.c.
References ast_channel::_bridge, ast_channel_tech::bridged_channel, and ast_channel::tech.
Referenced by __dahdi_exception(), _skinny_show_lines(), action_agents(), action_coreshowchannels(), agents_show(), agents_show_online(), ast_bridge_call(), ast_channel_masquerade(), ast_do_masquerade(), ast_rtp_set_vars(), ast_var_channel_bridge(), ast_var_channels_table(), 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(), local_queryoption(), mgcp_hangup(), mgcp_ss(), misdn_attempt_transfer(), mixmonitor_thread(), park_call_full(), schedule_delivery(), sip_hangup(), sip_set_rtp_peer(), skinny_transfer(), socket_process(), ss_thread(), start_spying(), startmon(), TransferCallStep1(), and unistim_hangup().
04957 { 04958 struct ast_channel *bridged; 04959 bridged = chan->_bridge; 04960 if (bridged && bridged->tech->bridged_channel) 04961 bridged = bridged->tech->bridged_channel(chan, bridged); 04962 return bridged; 04963 }
| 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 4252 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, and ast_channel::tech.
Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), attempt_reconnect(), begin_dial_channel(), connect_link(), dial_exec_full(), dial_transfer(), do_forward(), feature_request_and_dial(), findmeexec(), play_sound_file(), ring_entry(), rpt(), rpt_exec(), and wait_for_answer().
04253 { 04254 /* Place an outgoing call, but don't wait any longer than timeout ms before returning. 04255 If the remote end does not answer within the timeout, then do NOT hang up, but 04256 return anyway. */ 04257 int res = -1; 04258 /* Stop if we're a zombie or need a soft hangup */ 04259 ast_channel_lock(chan); 04260 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) { 04261 if (chan->cdr) { 04262 ast_set_flag(chan->cdr, AST_CDR_FLAG_DIALED); 04263 } 04264 if (chan->tech->call) 04265 res = chan->tech->call(chan, addr, timeout); 04266 ast_set_flag(chan, AST_FLAG_OUTGOING); 04267 } 04268 ast_channel_unlock(chan); 04269 return res; 04270 }
| struct ast_channel* ast_call_forward | ( | struct ast_channel * | caller, | |
| struct ast_channel * | orig, | |||
| int * | timeout, | |||
| int | format, | |||
| struct outgoing_helper * | oh, | |||
| int * | outstate | |||
| ) | [read] |
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 3977 of file channel.c.
References outgoing_helper::account, 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(), cause, ast_channel::cdr, CHANNEL_DEADLOCK_AVOIDANCE, ast_channel::cid, ast_callerid::cid_name, outgoing_helper::cid_name, ast_callerid::cid_num, outgoing_helper::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 feature_request_and_dial().
03978 { 03979 char tmpchan[256]; 03980 struct ast_channel *new = NULL; 03981 char *data, *type; 03982 int cause = 0; 03983 03984 /* gather data and request the new forward channel */ 03985 ast_copy_string(tmpchan, orig->call_forward, sizeof(tmpchan)); 03986 if ((data = strchr(tmpchan, '/'))) { 03987 *data++ = '\0'; 03988 type = tmpchan; 03989 } else { 03990 const char *forward_context; 03991 ast_channel_lock(orig); 03992 forward_context = pbx_builtin_getvar_helper(orig, "FORWARD_CONTEXT"); 03993 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", orig->call_forward, S_OR(forward_context, orig->context)); 03994 ast_channel_unlock(orig); 03995 data = tmpchan; 03996 type = "Local"; 03997 } 03998 if (!(new = ast_request(type, format, data, &cause))) { 03999 ast_log(LOG_NOTICE, "Unable to create channel for call forward to '%s/%s' (cause = %d)\n", type, data, cause); 04000 handle_cause(cause, outstate); 04001 ast_hangup(orig); 04002 return NULL; 04003 } 04004 04005 /* Copy/inherit important information into new channel */ 04006 if (oh) { 04007 if (oh->vars) { 04008 ast_set_variables(new, oh->vars); 04009 } 04010 if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) { 04011 ast_set_callerid(new, oh->cid_num, oh->cid_name, oh->cid_num); 04012 } 04013 if (oh->parent_channel) { 04014 ast_channel_inherit_variables(oh->parent_channel, new); 04015 ast_channel_datastore_inherit(oh->parent_channel, new); 04016 } 04017 if (oh->account) { 04018 ast_cdr_setaccount(new, oh->account); 04019 } 04020 } else if (caller) { /* no outgoing helper so use caller if avaliable */ 04021 ast_channel_inherit_variables(caller, new); 04022 ast_channel_datastore_inherit(caller, new); 04023 } 04024 04025 ast_channel_lock(orig); 04026 while (ast_channel_trylock(new)) { 04027 CHANNEL_DEADLOCK_AVOIDANCE(orig); 04028 } 04029 ast_copy_flags(new->cdr, orig->cdr, AST_CDR_FLAG_ORIGINATED); 04030 ast_string_field_set(new, accountcode, orig->accountcode); 04031 if (!ast_strlen_zero(orig->cid.cid_num) && !ast_strlen_zero(new->cid.cid_name)) { 04032 ast_set_callerid(new, orig->cid.cid_num, orig->cid.cid_name, orig->cid.cid_num); 04033 } 04034 ast_channel_unlock(new); 04035 ast_channel_unlock(orig); 04036 04037 /* call new channel */ 04038 if ((*timeout = ast_call(new, data, 0))) { 04039 ast_log(LOG_NOTICE, "Unable to call forward to channel %s/%s\n", type, (char *)data); 04040 ast_hangup(orig); 04041 ast_hangup(new); 04042 return NULL; 04043 } 04044 ast_hangup(orig); 04045 04046 return new; 04047 }
| void ast_cancel_shutdown | ( | void | ) |
Cancel a shutdown in progress.
Cancels an existing shutdown and returns to normal operation
Definition at line 509 of file channel.c.
Referenced by handle_abort_shutdown().
00510 { 00511 shutting_down = 0; 00512 }
| const char* ast_cause2str | ( | int | state | ) |
Gives the string form of a given hangup cause.
Gives the string form of a given cause code
| 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 629 of file channel.c.
References ARRAY_LEN, and causes.
Referenced by __transmit_response(), ast_do_masquerade(), ast_hangup(), dial_exec_full(), findmeexec(), sip_hangup(), and transmit_request_with_auth().
| void ast_change_name | ( | struct ast_channel * | chan, | |
| char * | newname | |||
| ) |
Change channel name.
Definition at line 4509 of file channel.c.
References ast_string_field_set, EVENT_FLAG_CALL, manager_event, and name.
Referenced by update_name().
04510 { 04511 manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", chan->name, newname, chan->uniqueid); 04512 ast_string_field_set(chan, name, newname); 04513 }
| 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, | |||
| ... | ||||
| ) | [read] |
Definition at line 6121 of file channel.c.
References __ast_channel_alloc_ap().
06125 { 06126 va_list ap1, ap2; 06127 struct ast_channel *result; 06128 06129 06130 va_start(ap1, name_fmt); 06131 va_start(ap2, name_fmt); 06132 result = __ast_channel_alloc_ap(needqueue, state, cid_num, cid_name, acctcode, exten, context, 06133 amaflag, __FILE__, __LINE__, __FUNCTION__, name_fmt, ap1, ap2); 06134 va_end(ap1); 06135 va_end(ap2); 06136 06137 return result; 06138 }
| 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 5279 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_SRCCHANGE, 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, ast_bridge_config::end_sound, EVENT_FLAG_CALL, ast_bridge_config::feature_timer, ast_bridge_config::features_callee, ast_bridge_config::features_caller, ast_bridge_config::firstpass, ast_bridge_config::flags, ast_channel::generator, LOG_WARNING, manager_bridge_event(), manager_event, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::nativeformats, ast_bridge_config::nexteventts, ast_bridge_config::play_warning, ast_channel::readformat, ast_channel_tech::send_digit_begin, ast_bridge_config::start_sound, ast_bridge_config::start_time, ast_channel::tech, ast_bridge_config::timelimit, update_bridge_vars(), ast_bridge_config::warning_freq, ast_bridge_config::warning_sound, and ast_channel::writeformat.
Referenced by ast_bridge_call().
05281 { 05282 struct ast_channel *who = NULL; 05283 enum ast_bridge_result res = AST_BRIDGE_COMPLETE; 05284 int nativefailed=0; 05285 int firstpass; 05286 int o0nativeformats; 05287 int o1nativeformats; 05288 long time_left_ms=0; 05289 char caller_warning = 0; 05290 char callee_warning = 0; 05291 05292 if (c0->_bridge) { 05293 ast_log(LOG_WARNING, "%s is already in a bridge with %s\n", 05294 c0->name, c0->_bridge->name); 05295 return -1; 05296 } 05297 if (c1->_bridge) { 05298 ast_log(LOG_WARNING, "%s is already in a bridge with %s\n", 05299 c1->name, c1->_bridge->name); 05300 return -1; 05301 } 05302 05303 /* Stop if we're a zombie or need a soft hangup */ 05304 if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || 05305 ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) 05306 return -1; 05307 05308 *fo = NULL; 05309 firstpass = config->firstpass; 05310 config->firstpass = 0; 05311 05312 if (ast_tvzero(config->start_time)) 05313 config->start_time = ast_tvnow(); 05314 time_left_ms = config->timelimit; 05315 05316 caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING); 05317 callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING); 05318 05319 if (config->start_sound && firstpass) { 05320 if (caller_warning) 05321 bridge_playfile(c0, c1, config->start_sound, time_left_ms / 1000); 05322 if (callee_warning) 05323 bridge_playfile(c1, c0, config->start_sound, time_left_ms / 1000); 05324 } 05325 05326 /* Keep track of bridge */ 05327 c0->_bridge = c1; 05328 c1->_bridge = c0; 05329 05330 05331 o0nativeformats = c0->nativeformats; 05332 o1nativeformats = c1->nativeformats; 05333 05334 if (config->feature_timer && !ast_tvzero(config->nexteventts)) { 05335 config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->feature_timer, 1000)); 05336 } else if (config->timelimit && firstpass) { 05337 config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000)); 05338 if (caller_warning || callee_warning) 05339 config->nexteventts = ast_tvsub(config->nexteventts, ast_samp2tv(config->play_warning, 1000)); 05340 } 05341 05342 if (!c0->tech->send_digit_begin) 05343 ast_set_flag(c1, AST_FLAG_END_DTMF_ONLY); 05344 if (!c1->tech->send_digit_begin) 05345 ast_set_flag(c0, AST_FLAG_END_DTMF_ONLY); 05346 manager_bridge_event(1, 1, c0, c1); 05347 05348 /* Before we enter in and bridge these two together tell them both the source of audio has changed */ 05349 ast_indicate(c0, AST_CONTROL_SRCCHANGE); 05350 ast_indicate(c1, AST_CONTROL_SRCCHANGE); 05351 05352 for (/* ever */;;) { 05353 struct timeval now = { 0, }; 05354 int to; 05355 05356 to = -1; 05357 05358 if (!ast_tvzero(config->nexteventts)) { 05359 now = ast_tvnow(); 05360 to = ast_tvdiff_ms(config->nexteventts, now); 05361 if (to <= 0) { 05362 if (!config->timelimit) { 05363 res = AST_BRIDGE_COMPLETE; 05364 break; 05365 } 05366 to = 0; 05367 } 05368 } 05369 05370 if (config->timelimit) { 05371 time_left_ms = config->timelimit - ast_tvdiff_ms(now, config->start_time); 05372 if (time_left_ms < to) 05373 to = time_left_ms; 05374 05375 if (time_left_ms <= 0) { 05376 if (caller_warning && config->end_sound) 05377 bridge_playfile(c0, c1, config->end_sound, 0); 05378 if (callee_warning && config->end_sound) 05379 bridge_playfile(c1, c0, config->end_sound, 0); 05380 *fo = NULL; 05381 if (who) 05382 *rc = who; 05383 res = 0; 05384 break; 05385 } 05386 05387 if (!to) { 05388 if (time_left_ms >= 5000 && config->warning_sound && config->play_warning && ast_test_flag(config, AST_FEATURE_WARNING_ACTIVE)) { 05389 int t = (time_left_ms + 500) / 1000; /* round to nearest second */ 05390 if (caller_warning) 05391 bridge_playfile(c0, c1, config->warning_sound, t); 05392 if (callee_warning) 05393 bridge_playfile(c1, c0, config->warning_sound, t); 05394 } 05395 if (config->warning_freq && (time_left_ms > (config->warning_freq + 5000))) 05396 config->nexteventts = ast_tvadd(config->nexteventts, ast_samp2tv(config->warning_freq, 1000)); 05397 else 05398 config->nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000)); 05399 } 05400 ast_clear_flag(config, AST_FEATURE_WARNING_ACTIVE); 05401 } 05402 05403 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) { 05404 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 05405 c0->_softhangup = 0; 05406 if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 05407 c1->_softhangup = 0; 05408 c0->_bridge = c1; 05409 c1->_bridge = c0; 05410 ast_debug(1, "Unbridge signal received. Ending native bridge.\n"); 05411 continue; 05412 } 05413 05414 /* Stop if we're a zombie or need a soft hangup */ 05415 if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || 05416 ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) { 05417 *fo = NULL; 05418 if (who) 05419 *rc = who; 05420 res = 0; 05421 ast_debug(1, "Bridge stops because we're zombie or need a soft hangup: c0=%s, c1=%s, flags: %s,%s,%s,%s\n", 05422 c0->name, c1->name, 05423 ast_test_flag(c0, AST_FLAG_ZOMBIE) ? "Yes" : "No", 05424 ast_check_hangup(c0) ? "Yes" : "No", 05425 ast_test_flag(c1, AST_FLAG_ZOMBIE) ? "Yes" : "No", 05426 ast_check_hangup(c1) ? "Yes" : "No"); 05427 break; 05428 } 05429 05430 update_bridge_vars(c0, c1); 05431 05432 bridge_play_sounds(c0, c1); 05433 05434 if (c0->tech->bridge && 05435 /* if < 1 ms remains use generic bridging for accurate timing */ 05436 (!config->timelimit || to > 1000 || to == 0) && 05437 (c0->tech->bridge == c1->tech->bridge) && 05438 !nativefailed && !c0->monitor && !c1->monitor && 05439 !c0->audiohooks && !c1->audiohooks && 05440 !c0->masq && !c0->masqr && !c1->masq && !c1->masqr) { 05441 int timeoutms = to - 1000 > 0 ? to - 1000 : to; 05442 /* Looks like they share a bridge method and nothing else is in the way */ 05443 ast_set_flag(c0, AST_FLAG_NBRIDGE); 05444 ast_set_flag(c1, AST_FLAG_NBRIDGE); 05445 if ((res = c0->tech->bridge(c0, c1, config->flags, fo, rc, timeoutms)) == AST_BRIDGE_COMPLETE) { 05446 /* \todo XXX here should check that cid_num is not NULL */ 05447 manager_event(EVENT_FLAG_CALL, "Unlink", 05448 "Channel1: %s\r\n" 05449 "Channel2: %s\r\n" 05450 "Uniqueid1: %s\r\n" 05451 "Uniqueid2: %s\r\n" 05452 "CallerID1: %s\r\n" 05453 "CallerID2: %s\r\n", 05454 c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); 05455 ast_debug(1, "Returning from native bridge, channels: %s, %s\n", c0->name, c1->name); 05456 05457 ast_clear_flag(c0, AST_FLAG_NBRIDGE); 05458 ast_clear_flag(c1, AST_FLAG_NBRIDGE); 05459 05460 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 05461 continue; 05462 05463 c0->_bridge = NULL; 05464 c1->_bridge = NULL; 05465 05466 return res; 05467 } else { 05468 ast_clear_flag(c0, AST_FLAG_NBRIDGE); 05469 ast_clear_flag(c1, AST_FLAG_NBRIDGE); 05470 } 05471 switch (res) { 05472 case AST_BRIDGE_RETRY: 05473 if (config->play_warning) { 05474 ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE); 05475 } 05476 continue; 05477 default: 05478 ast_verb(3, "Native bridging %s and %s ended\n", c0->name, c1->name); 05479 /* fallthrough */ 05480 case AST_BRIDGE_FAILED_NOWARN: 05481 nativefailed++; 05482 break; 05483 } 05484 } 05485 05486 if (((c0->writeformat != c1->readformat) || (c0->readformat != c1->writeformat) || 05487 (c0->nativeformats != o0nativeformats) || (c1->nativeformats != o1nativeformats)) && 05488 !(c0->generator || c1->generator)) { 05489 if (ast_channel_make_compatible(c0, c1)) { 05490 ast_log(LOG_WARNING, "Can't make %s and %s compatible\n", c0->name, c1->name); 05491 manager_bridge_event(0, 1, c0, c1); 05492 return AST_BRIDGE_FAILED; 05493 } 05494 o0nativeformats = c0->nativeformats; 05495 o1nativeformats = c1->nativeformats; 05496 } 05497 05498 update_bridge_vars(c0, c1); 05499 05500 res = ast_generic_bridge(c0, c1, config, fo, rc, config->nexteventts); 05501 if (res != AST_BRIDGE_RETRY) { 05502 break; 05503 } else if (config->feature_timer) { 05504 /* feature timer expired but has not been updated, sending to ast_bridge_call to do so */ 05505 break; 05506 } 05507 } 05508 05509 ast_clear_flag(c0, AST_FLAG_END_DTMF_ONLY); 05510 ast_clear_flag(c1, AST_FLAG_END_DTMF_ONLY); 05511 05512 /* Now that we have broken the bridge the source will change yet again */ 05513 ast_indicate(c0, AST_CONTROL_SRCUPDATE); 05514 ast_indicate(c1, AST_CONTROL_SRCUPDATE); 05515 05516 c0->_bridge = NULL; 05517 c1->_bridge = NULL; 05518 05519 /* \todo XXX here should check that cid_num is not NULL */ 05520 manager_event(EVENT_FLAG_CALL, "Unlink", 05521 "Channel1: %s\r\n" 05522 "Channel2: %s\r\n" 05523 "Uniqueid1: %s\r\n" 05524 "Uniqueid2: %s\r\n" 05525 "CallerID1: %s\r\n" 05526 "CallerID2: %s\r\n", 05527 c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); 05528 ast_debug(1, "Bridge stops bridging channels %s and %s\n", c0->name, c1->name); 05529 05530 return res; 05531 }
| 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 550 of file channel.c.
References ast_channel_cmpwhentohangup_tv().
00551 { 00552 struct timeval when = { offset, }; 00553 return ast_channel_cmpwhentohangup_tv(chan, when); 00554 }
| int ast_channel_cmpwhentohangup_tv | ( | struct ast_channel * | chan, | |
| struct timeval | offset | |||
| ) |
Compare a offset with when to hangup channel.
Compare a offset with the settings of when to hang a channel up.
Definition at line 535 of file channel.c.
References ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), and ast_channel::whentohangup.
Referenced by ast_channel_cmpwhentohangup().
00536 { 00537 struct timeval whentohangup; 00538 00539 if (ast_tvzero(chan->whentohangup)) 00540 return ast_tvzero(offset) ? 0 : -1; 00541 00542 if (ast_tvzero(offset)) 00543 return 1; 00544 00545 whentohangup = ast_tvadd(offset, ast_tvnow()); 00546 00547 return ast_tvdiff_ms(whentohangup, chan->whentohangup); 00548 }
| 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 1594 of file channel.c.
References AST_LIST_INSERT_HEAD.
Referenced by _macro_exec(), acf_curlopt_write(), acf_iaxvar_write(), acf_odbc_read(), add_features_datastores(), add_to_agi(), apply_plc(), ast_iax2_new(), audiohook_volume_get(), authenticate_reply(), dial_exec_full(), dundi_query_read(), enable_jack_hook(), enum_query_read(), find_transaction(), 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().
01595 { 01596 int res = 0; 01597 01598 AST_LIST_INSERT_HEAD(&chan->datastores, datastore, entry); 01599 01600 return res; 01601 }
| struct ast_datastore* ast_channel_datastore_alloc | ( | const struct ast_datastore_info * | info, | |
| const char * | uid | |||
| ) | [read] |
Create a channel data store object.
Definition at line 1567 of file channel.c.
References ast_datastore_alloc.
01568 { 01569 return ast_datastore_alloc(info, uid); 01570 }
| struct ast_datastore* ast_channel_datastore_find | ( | struct ast_channel * | chan, | |
| const struct ast_datastore_info * | info, | |||
| const char * | uid | |||
| ) | [read] |
Find a datastore on a channel.
| pointer | to the datastore if found | |
| NULL | if not found |
Definition at line 1608 of file channel.c.
References AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_datastore::info, and ast_datastore::uid.
Referenced by _macro_exec(), acf_curl_exec(), acf_curlopt_read(), acf_curlopt_write(), acf_exception_read(), acf_fetch(), acf_iaxvar_read(), acf_iaxvar_write(), add_agi_cmd(), add_features_datastores(), add_to_agi(), apply_plc(), ast_odbc_retrieve_transaction_obj(), 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(), find_transaction(), 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(), mark_transaction_active(), park_exec_full(), pbx_builtin_raise_exception(), pop_exec(), queue_transfer_fixup(), release_transaction(), 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().
01609 { 01610 struct ast_datastore *datastore = NULL; 01611 01612 if (info == NULL) 01613 return NULL; 01614 01615 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore, entry) { 01616 if (datastore->info != info) { 01617 continue; 01618 } 01619 01620 if (uid == NULL) { 01621 /* matched by type only */ 01622 break; 01623 } 01624 01625 if ((datastore->uid != NULL) && !strcasecmp(uid, datastore->uid)) { 01626 /* Matched by type AND uid */ 01627 break; 01628 } 01629 } 01630 AST_LIST_TRAVERSE_SAFE_END; 01631 01632 return datastore; 01633 }
| int ast_channel_datastore_free | ( | struct ast_datastore * | datastore | ) |
Free a channel data store object.
Definition at line 1572 of file channel.c.
References ast_datastore_free().
01573 { 01574 return ast_datastore_free(datastore); 01575 }
| int ast_channel_datastore_inherit | ( | struct ast_channel * | from, | |
| struct ast_channel * | to | |||
| ) |
Inherit datastores from a parent to a child.
Definition at line 1577 of file channel.c.
References ast_datastore_alloc, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_datastore::data, DATASTORE_INHERIT_FOREVER, ast_datastore_info::duplicate, ast_datastore::info, ast_datastore::inheritance, and ast_datastore::uid.
Referenced by __ast_request_and_dial(), ast_call_forward(), begin_dial_channel(), dial_exec_full(), do_forward(), findmeexec(), local_call(), ring_entry(), and wait_for_answer().
01578 { 01579 struct ast_datastore *datastore = NULL, *datastore2; 01580 01581 AST_LIST_TRAVERSE(&from->datastores, datastore, entry) { 01582 if (datastore->inheritance > 0) { 01583 datastore2 = ast_datastore_alloc(datastore->info, datastore->uid); 01584 if (datastore2) { 01585 datastore2->data = datastore->info->duplicate ? datastore->info->duplicate(datastore->data) : NULL; 01586 datastore2->inheritance = datastore->inheritance == DATASTORE_INHERIT_FOREVER ? DATASTORE_INHERIT_FOREVER : datastore->inheritance - 1; 01587 AST_LIST_INSERT_TAIL(&to->datastores, datastore2, entry); 01588 } 01589 } 01590 } 01591 return 0; 01592 }
| 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 1603 of file channel.c.
References AST_LIST_REMOVE.
Referenced by acf_fetch(), adjust_frame_for_plc(), 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().
01604 { 01605 return AST_LIST_REMOVE(&chan->datastores, datastore, entry) ? 0 : -1; 01606 }
| int ast_channel_defer_dtmf | ( | struct ast_channel * | chan | ) |
Set defer DTMF flag on channel.
Defers DTMF
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 1152 of file channel.c.
References AST_FLAG_DEFER_DTMF, ast_set_flag, and ast_test_flag.
Referenced by __adsi_transmit_messages(), and find_cache().
01153 { 01154 int pre = 0; 01155 01156 if (chan) { 01157 pre = ast_test_flag(chan, AST_FLAG_DEFER_DTMF); 01158 ast_set_flag(chan, AST_FLAG_DEFER_DTMF); 01159 } 01160 return pre; 01161 }
| 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 5181 of file channel.c.
References ast_channel_tech::early_bridge, and ast_channel::tech.
Referenced by dial_exec_full(), and wait_for_answer().
05182 { 05183 /* Make sure we can early bridge, if not error out */ 05184 if (!c0->tech->early_bridge || (c1 && (!c1->tech->early_bridge || c0->tech->early_bridge != c1->tech->early_bridge))) 05185 return -1; 05186 05187 return c0->tech->early_bridge(c0, c1); 05188 }
| void ast_channel_free | ( | struct ast_channel * | chan | ) |
Free a channel structure.
Definition at line 1448 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_tone_zone_unref(), ast_translator_free_path(), ast_var_delete(), ast_channel::cdr, ast_channel::cid, f, free, free_cid(), ast_channel::lock_dont_use, LOG_WARNING, ast_channel::monitor, ast_channel::music_state, name, ast_channel::pbx, ast_channel::readtrans, ast_channel::sched, sched_context_destroy(), ast_channel_monitor::stop, ast_channel::tech_pvt, ast_channel::timer, ast_channel::varshead, ast_channel::writetrans, and ast_channel::zone.
Referenced by acf_odbc_read(), acf_odbc_write(), action_getvar(), agent_cleanup(), agent_new(), ast_do_masquerade(), ast_hangup(), ast_iax2_new(), ast_pbx_outgoing_cdr_failed(), bridge_request(), cli_odbc_read(), cli_odbc_write(), gtalk_newcall(), local_new(), make_email_file(), pbx_substitute_variables_helper_full(), rotate_file(), sendmail(), and sendpage().
01449 { 01450 int fd; 01451 #ifdef HAVE_EPOLL 01452 int i; 01453 #endif 01454 struct ast_var_t *vardata; 01455 struct ast_frame *f; 01456 struct varshead *headp; 01457 struct ast_datastore *datastore = NULL; 01458 char name[AST_CHANNEL_NAME], *dashptr; 01459 int inlist; 01460 01461 headp=&chan->varshead; 01462 01463 inlist = ast_test_flag(chan, AST_FLAG_IN_CHANNEL_LIST); 01464 if (inlist) { 01465 AST_RWLIST_WRLOCK(&channels); 01466 if (!AST_RWLIST_REMOVE(&channels, chan, chan_list)) { 01467 ast_debug(1, "Unable to find channel in list to free. Assuming it has already been done.\n"); 01468 } 01469 /* Lock and unlock the channel just to be sure nobody has it locked still 01470 due to a reference retrieved from the channel list. */ 01471 ast_channel_lock(chan); 01472 ast_channel_unlock(chan); 01473 } 01474 01475 /* Get rid of each of the data stores on the channel */ 01476 ast_channel_lock(chan); 01477 while ((datastore = AST_LIST_REMOVE_HEAD(&chan->datastores, entry))) 01478 /* Free the data store */ 01479 ast_datastore_free(datastore); 01480 ast_channel_unlock(chan); 01481 01482 /* Lock and unlock the channel just to be sure nobody has it locked still 01483 due to a reference that was stored in a datastore. (i.e. app_chanspy) */ 01484 ast_channel_lock(chan); 01485 ast_channel_unlock(chan); 01486 01487 if (chan->tech_pvt) { 01488 ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name); 01489 ast_free(chan->tech_pvt); 01490 } 01491 01492 if (chan->sched) 01493 sched_context_destroy(chan->sched); 01494 01495 ast_copy_string(name, chan->name, sizeof(name)); 01496 if ((dashptr = strrchr(name, '-'))) { 01497 *dashptr = '\0'; 01498 } 01499 01500 /* Stop monitoring */ 01501 if (chan->monitor) 01502 chan->monitor->stop( chan, 0 ); 01503 01504 /* If there is native format music-on-hold state, free it */ 01505 if (chan->music_state) 01506 ast_moh_cleanup(chan); 01507 01508 /* Free translators */ 01509 if (chan->readtrans) 01510 ast_translator_free_path(chan->readtrans); 01511 if (chan->writetrans) 01512 ast_translator_free_path(chan->writetrans); 01513 if (chan->pbx) 01514 ast_log(LOG_WARNING, "PBX may not have been terminated properly on '%s'\n", chan->name); 01515 free_cid(&chan->cid); 01516 /* Close pipes if appropriate */ 01517 if ((fd = chan->alertpipe[0]) > -1) 01518 close(fd); 01519 if ((fd = chan->alertpipe[1]) > -1) 01520 close(fd); 01521 if (chan->timer) { 01522 ast_timer_close(chan->timer); 01523 } 01524 #ifdef HAVE_EPOLL 01525 for (i = 0; i < AST_MAX_FDS; i++) { 01526 if (chan->epfd_data[i]) 01527 free(chan->epfd_data[i]); 01528 } 01529 close(chan->epfd); 01530 #endif 01531 while ((f = AST_LIST_REMOVE_HEAD(&chan->readq, frame_list))) 01532 ast_frfree(f); 01533 01534 /* loop over the variables list, freeing all data and deleting list items */ 01535 /* no need to lock the list, as the channel is already locked */ 01536 01537 while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries))) 01538 ast_var_delete(vardata); 01539 01540 ast_app_group_discard(chan); 01541 01542 /* Destroy the jitterbuffer */ 01543 ast_jb_destroy(chan); 01544 01545 if (chan->cdr) { 01546 ast_cdr_discard(chan->cdr); 01547 chan->cdr = NULL; 01548 } 01549 01550 if (chan->zone) { 01551 chan->zone = ast_tone_zone_unref(chan->zone); 01552 } 01553 01554 ast_mutex_destroy(&chan->lock_dont_use); 01555 01556 ast_string_field_free_memory(chan); 01557 ast_free(chan); 01558 if (inlist) 01559 AST_RWLIST_UNLOCK(&channels); 01560 01561 /* Queue an unknown state, because, while we know that this particular 01562 * instance is dead, we don't know the state of all other possible 01563 * instances. */ 01564 ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, name); 01565 }
| 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 |
Scans all channel variables in the parent channel, looking for those that should be copied into the child channel. Variables whose names begin with a single '_' are copied into the child channel with the prefix removed. Variables whose names begin with '__' are copied into the child channel with their names unchanged.
Definition at line 4515 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(), and ast_channel::varshead.
Referenced by __ast_request_and_dial(), agent_call(), ast_call_forward(), begin_dial_channel(), dial_exec_full(), dial_transfer(), do_forward(), feature_request_and_dial(), findmeexec(), ring_entry(), and wait_for_answer().
04516 { 04517 struct ast_var_t *current, *newvar; 04518 const char *varname; 04519 04520 AST_LIST_TRAVERSE(&parent->varshead, current, entries) { 04521 int vartype = 0; 04522 04523 varname = ast_var_full_name(current); 04524 if (!varname) 04525 continue; 04526 04527 if (varname[0] == '_') { 04528 vartype = 1; 04529 if (varname[1] == '_') 04530 vartype = 2; 04531 } 04532 04533 switch (vartype) { 04534 case 1: 04535 newvar = ast_var_assign(&varname[1], ast_var_value(current)); 04536 if (newvar) { 04537 AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries); 04538 ast_debug(1, "Copying soft-transferable variable %s.\n", ast_var_name(newvar)); 04539 } 04540 break; 04541 case 2: 04542 newvar = ast_var_assign(varname, ast_var_value(current)); 04543 if (newvar) { 04544 AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries); 04545 ast_debug(1, "Copying hard-transferable variable %s.\n", ast_var_name(newvar)); 04546 } 04547 break; 04548 default: 04549 ast_debug(1, "Not copying variable %s.\n", ast_var_name(current)); 04550 break; 04551 } 04552 } 04553 }
| 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 4413 of file channel.c.
References ast_channel_make_compatible_helper().
Referenced by action_bridge(), app_exec(), ast_channel_bridge(), bridge_exec(), check_compat(), dial_exec_full(), do_forward(), multiplexed_bridge_join(), park_exec_full(), simple_bridge_join(), try_calling(), and wait_for_answer().
04414 { 04415 /* Some callers do not check return code, and we must try to set all call legs correctly */ 04416 int rc = 0; 04417 04418 /* Set up translation from the chan to the peer */ 04419 rc = ast_channel_make_compatible_helper(chan, peer); 04420 04421 if (rc < 0) 04422 return rc; 04423 04424 /* Set up translation from the peer to the chan */ 04425 rc = ast_channel_make_compatible_helper(peer, chan); 04426 04427 return rc; 04428 }
| 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 4368 of file channel.c.
References AST_FORMAT_AUDIO_MASK, AST_FORMAT_SLINEAR, ast_log(), ast_opt_generic_plc, 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::nativeformats, ast_channel::readformat, and ast_channel::writeformat.
Referenced by ast_channel_make_compatible().
04369 { 04370 int src; 04371 int dst; 04372 int use_slin; 04373 04374 if (from->readformat == to->writeformat && from->writeformat == to->readformat) { 04375 /* Already compatible! Moving on ... */ 04376 return 0; 04377 } 04378 04379 /* Set up translation from the 'from' channel to the 'to' channel */ 04380 src = from->nativeformats; 04381 dst = to->nativeformats; 04382 04383 /* If there's no audio in this call, don't bother with trying to find a translation path */ 04384 if ((src & AST_FORMAT_AUDIO_MASK) == 0 || (dst & AST_FORMAT_AUDIO_MASK) == 0) 04385 return 0; 04386 04387 if (ast_translator_best_choice(&dst, &src) < 0) { 04388 ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", from->name, src, to->name, dst); 04389 return -1; 04390 } 04391 04392 /* if the best path is not 'pass through', then 04393 * transcoding is needed; if desired, force transcode path 04394 * to use SLINEAR between channels, but only if there is 04395 * no direct conversion available. If generic PLC is 04396 * desired, then transcoding via SLINEAR is a requirement 04397 */ 04398 use_slin = (src == AST_FORMAT_SLINEAR || dst == AST_FORMAT_SLINEAR); 04399 if ((src != dst) && (ast_opt_generic_plc || ast_opt_transcode_via_slin) && 04400 (ast_translate_path_steps(dst, src) != 1 || use_slin)) 04401 dst = AST_FORMAT_SLINEAR; 04402 if (ast_set_read_format(from, dst) < 0) { 04403 ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", from->name, dst); 04404 return -1; 04405 } 04406 if (ast_set_write_format(to, dst) < 0) { 04407 ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", to->name, dst); 04408 return -1; 04409 } 04410 return 0; 04411 }
| 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 |
This is a very strange and freaky function used primarily for transfer. Suppose that "original" and "clone" are two channels in random situations. This function takes the guts out of "clone" and puts them into the "original" channel, then alerts the channel driver of the change, asking it to fixup any private information (like the p->owner pointer) that is affected by the change. The physical layer of the original channel is hung up.
Definition at line 4430 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, 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().
04431 { 04432 int res = -1; 04433 struct ast_channel *final_orig, *final_clone, *base; 04434 04435 retrymasq: 04436 final_orig = original; 04437 final_clone = clonechan; 04438 04439 ast_channel_lock(original); 04440 while (ast_channel_trylock(clonechan)) { 04441 ast_channel_unlock(original); 04442 usleep(1); 04443 ast_channel_lock(original); 04444 } 04445 04446 /* each of these channels may be sitting behind a channel proxy (i.e. chan_agent) 04447 and if so, we don't really want to masquerade it, but its proxy */ 04448 if (original->_bridge && (original->_bridge != ast_bridged_channel(original)) && (original->_bridge->_bridge != original)) 04449 final_orig = original->_bridge; 04450 04451 if (clonechan->_bridge && (clonechan->_bridge != ast_bridged_channel(clonechan)) && (clonechan->_bridge->_bridge != clonechan)) 04452 final_clone = clonechan->_bridge; 04453 04454 if (final_clone->tech->get_base_channel && (base = final_clone->tech->get_base_channel(final_clone))) { 04455 final_clone = base; 04456 } 04457 04458 if ((final_orig != original) || (final_clone != clonechan)) { 04459 /* Lots and lots of deadlock avoidance. The main one we're competing with 04460 * is ast_write(), which locks channels recursively, when working with a 04461 * proxy channel. */ 04462 if (ast_channel_trylock(final_orig)) { 04463 ast_channel_unlock(clonechan); 04464 ast_channel_unlock(original); 04465 goto retrymasq; 04466 } 04467 if (ast_channel_trylock(final_clone)) { 04468 ast_channel_unlock(final_orig); 04469 ast_channel_unlock(clonechan); 04470 ast_channel_unlock(original); 04471 goto retrymasq; 04472 } 04473 ast_channel_unlock(clonechan); 04474 ast_channel_unlock(original); 04475 original = final_orig; 04476 clonechan = final_clone; 04477 } 04478 04479 if (original == clonechan) { 04480 ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name); 04481 ast_channel_unlock(clonechan); 04482 ast_channel_unlock(original); 04483 return -1; 04484 } 04485 04486 ast_debug(1, "Planning to masquerade channel %s into the structure of %s\n", 04487 clonechan->name, original->name); 04488 if (original->masq) { 04489 ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", 04490 original->masq->name, original->name); 04491 } else if (clonechan->masqr) { 04492 ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", 04493 clonechan->name, clonechan->masqr->name); 04494 } else { 04495 original->masq = clonechan; 04496 clonechan->masqr = original; 04497 ast_queue_frame(original, &ast_null_frame); 04498 ast_queue_frame(clonechan, &ast_null_frame); 04499 ast_debug(1, "Done planning to masquerade channel %s into the structure of %s\n", clonechan->name, original->name); 04500 res = 0; 04501 } 04502 04503 ast_channel_unlock(clonechan); 04504 ast_channel_unlock(original); 04505 04506 return res; 04507 }
| int ast_channel_queryoption | ( | struct ast_channel * | channel, | |
| int | option, | |||
| void * | data, | |||
| int * | datalen, | |||
| int | block | |||
| ) |
Checks the value of an option
Query the value of an option Works similarly to setoption except only reads the options.
Definition at line 5547 of file channel.c.
References ast_log(), errno, LOG_ERROR, ast_channel_tech::queryoption, and ast_channel::tech.
Referenced by ast_channel_get_t38_state(), and local_queryoption().
05548 { 05549 if (!chan->tech->queryoption) { 05550 errno = ENOSYS; 05551 return -1; 05552 } 05553 05554 if (block) 05555 ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n"); 05556 05557 return chan->tech->queryoption(chan, option, data, datalen); 05558 }
| 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 3941 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().
03942 { 03943 switch (reason) /* the following appear to be the only ones actually returned by request_and_dial */ 03944 { 03945 case 0: 03946 return "Call Failure (not BUSY, and not NO_ANSWER, maybe Circuit busy or down?)"; 03947 case AST_CONTROL_HANGUP: 03948 return "Hangup"; 03949 case AST_CONTROL_RING: 03950 return "Local Ring"; 03951 case AST_CONTROL_RINGING: 03952 return "Remote end Ringing"; 03953 case AST_CONTROL_ANSWER: 03954 return "Remote end has Answered"; 03955 case AST_CONTROL_BUSY: 03956 return "Remote end is Busy"; 03957 case AST_CONTROL_CONGESTION: 03958 return "Congestion (circuits busy)"; 03959 default: 03960 return "Unknown Reason!!"; 03961 } 03962 }
| int ast_channel_register | ( | const struct ast_channel_tech * | tech | ) |
Register a new telephony channel in Asterisk.
Register a channel technology (a new channel driver) Called by a channel module to register the kind of channels it supports.
Definition at line 557 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, ast_channel_tech::description, LOG_WARNING, chanlist::tech, and ast_channel_tech::type.
Referenced by load_module(), and unload_module().
00558 { 00559 struct chanlist *chan; 00560 00561 AST_RWLIST_WRLOCK(&channels); 00562 00563 AST_LIST_TRAVERSE(&backends, chan, list) { 00564 if (!strcasecmp(tech->type, chan->tech->type)) { 00565 ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type); 00566 AST_RWLIST_UNLOCK(&channels); 00567 return -1; 00568 } 00569 } 00570 00571 if (!(chan = ast_calloc(1, sizeof(*chan)))) { 00572 AST_RWLIST_UNLOCK(&channels); 00573 return -1; 00574 } 00575 chan->tech = tech; 00576 AST_LIST_INSERT_HEAD(&backends, chan, list); 00577 00578 ast_debug(1, "Registered handler for '%s' (%s)\n", chan->tech->type, chan->tech->description); 00579 00580 ast_verb(2, "Registered channel type '%s' (%s)\n", chan->tech->type, chan->tech->description); 00581 00582 AST_RWLIST_UNLOCK(&channels); 00583 return 0; 00584 }
| struct ast_channel* ast_channel_search_locked | ( | int(*)(struct ast_channel *, void *) | is_match, | |
| void * | data | |||
| ) | [read] |
Search for a channel based on the passed channel matching callback (first match) and return it, locked.
Search for a channel based on the passed channel matching callback Search for a channel based on the specified is_match callback, and return the first channel that we match. When returned, the channel will be locked. Note that the is_match callback is called with the passed channel locked, and should return 0 if there is no match, and non-zero if there is.
Definition at line 1316 of file channel.c.
References ast_channel_lock, ast_channel_unlock, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, and AST_RWLIST_UNLOCK.
Referenced by ast_pickup_call(), pickup_by_exten(), pickup_by_mark(), and transmit_state_notify().
01317 { 01318 struct ast_channel *c = NULL; 01319 01320 AST_RWLIST_RDLOCK(&channels); 01321 AST_RWLIST_TRAVERSE(&channels, c, chan_list) { 01322 ast_channel_lock(c); 01323 if (is_match(c, data)) { 01324 break; 01325 } 01326 ast_channel_unlock(c); 01327 } 01328 AST_RWLIST_UNLOCK(&channels); 01329 01330 return c; 01331 }
| int ast_channel_sendhtml | ( | struct ast_channel * | channel, | |
| int | subclass, | |||
| const char * | data, | |||
| int | datalen | |||
| ) |
Sends HTML on given channel
Send HTML or URL on link. Returns 0 on success or -1 on failure
Definition at line 4355 of file channel.c.
References ast_channel_tech::send_html, and ast_channel::tech.
Referenced by agent_sendhtml(), ast_channel_sendurl(), and wait_for_answer().
| int ast_channel_sendurl | ( | struct ast_channel * | channel, | |
| const char * | url | |||
| ) |
Sends a URL on a given link
Send URL on link. Returns 0 on success or -1 on failure
Definition at line 4362 of file channel.c.
References ast_channel_sendhtml(), and AST_HTML_URL.
Referenced by dial_exec_full(), sendurl_exec(), and try_calling().
04363 { 04364 return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1); 04365 }
| void ast_channel_set_fd | ( | struct ast_channel * | chan, | |
| int | which, | |||
| int | fd | |||
| ) |
Set the file descriptor on the channel
Definition at line 1636 of file channel.c.
References ast_calloc, ast_epoll_data::chan, ast_channel::fds, free, and ast_epoll_data::which.
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(), setformat(), sip_new(), skinny_new(), start_rtp(), and swap_subs().
01637 { 01638 #ifdef HAVE_EPOLL 01639 struct epoll_event ev; 01640 struct ast_epoll_data *aed = NULL; 01641 01642 if (chan->fds[which] > -1) { 01643 epoll_ctl(chan->epfd, EPOLL_CTL_DEL, chan->fds[which], &ev); 01644 aed = chan->epfd_data[which]; 01645 } 01646 01647 /* If this new fd is valid, add it to the epoll */ 01648 if (fd > -1) { 01649 if (!aed && (!(aed = ast_calloc(1, sizeof(*aed))))) 01650 return; 01651 01652 chan->epfd_data[which] = aed; 01653 aed->chan = chan; 01654 aed->which = which; 01655 01656 ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP; 01657 ev.data.ptr = aed; 01658 epoll_ctl(chan->epfd, EPOLL_CTL_ADD, fd, &ev); 01659 } else if (aed) { 01660 /* We don't have to keep around this epoll data structure now */ 01661 free(aed); 01662 chan->epfd_data[which] = NULL; 01663 } 01664 #endif 01665 chan->fds[which] = fd; 01666 return; 01667 }
| int ast_channel_setoption | ( | struct ast_channel * | channel, | |
| int | option, | |||
| void * | data, | |||
| int | datalen, | |||
| int | block | |||
| ) |
Sets an option on a channel.
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 5534 of file channel.c.
References ast_log(), 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(), try_calling(), and vm_forwardoptions().
| 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 |
This function sets the absolute time out on a channel (when to hang up).
Definition at line 528 of file channel.c.
References ast_channel_setwhentohangup_tv().
00529 { 00530 struct timeval when = { offset, }; 00531 ast_channel_setwhentohangup_tv(chan, when); 00532 }
| void ast_channel_setwhentohangup_tv | ( | struct ast_channel * | chan, | |
| struct timeval | offset | |||
| ) |
Set when to hangup channel.
Set when to hang a channel up.
Definition at line 521 of file channel.c.
References ast_null_frame, ast_queue_frame(), ast_tvadd(), ast_tvnow(), ast_tvzero(), and ast_channel::whentohangup.
Referenced by action_timeout(), ast_channel_setwhentohangup(), handle_autohangup(), and timeout_write().
00522 { 00523 chan->whentohangup = ast_tvzero(offset) ? offset : ast_tvadd(offset, ast_tvnow()); 00524 ast_queue_frame(chan, &ast_null_frame); 00525 return; 00526 }
| struct ast_silence_generator* ast_channel_start_silence_generator | ( | struct ast_channel * | chan | ) | [read] |
Starts a silence generator on the given channel.
| chan | The channel to generate silence on |
This function will cause SLINEAR silence to be generated on the supplied channel until it is disabled; if the channel cannot be put into SLINEAR mode then the function will fail.
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 5885 of file channel.c.
References ast_activate_generator(), ast_calloc, ast_debug, AST_FORMAT_SLINEAR, ast_free, ast_log(), ast_set_write_format(), LOG_ERROR, ast_silence_generator::old_write_format, and ast_channel::writeformat.
Referenced by __ast_play_and_record(), ast_dtmf_stream(), ast_safe_sleep_conditional(), channel_spy(), record_exec(), TransferCallStep1(), waitfor_exec(), and waitforring_exec().
05886 { 05887 struct ast_silence_generator *state; 05888 05889 if (!(state = ast_calloc(1, sizeof(*state)))) { 05890 return NULL; 05891 } 05892 05893 state->old_write_format = chan->writeformat; 05894 05895 if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) { 05896 ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n"); 05897 ast_free(state); 05898 return NULL; 05899 } 05900 05901 ast_activate_generator(chan, &silence_generator, state); 05902 05903 ast_debug(1, "Started silence generator on '%s'\n", chan->name); 05904 05905 return state; 05906 }
| 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. |
This function will stop the operating silence generator and return the channel to its previous write format.
Definition at line 5908 of file channel.c.
References ast_deactivate_generator(), ast_debug, ast_free, ast_log(), ast_set_write_format(), LOG_ERROR, 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(), record_exec(), unistim_hangup(), waitfor_exec(), and waitforring_exec().
05909 { 05910 if (!state) 05911 return; 05912 05913 ast_deactivate_generator(chan); 05914 05915 ast_debug(1, "Stopped silence generator on '%s'\n", chan->name); 05916 05917 if (ast_set_write_format(chan, state->old_write_format) < 0) 05918 ast_log(LOG_ERROR, "Could not return write format to its original state\n"); 05919 05920 ast_free(state); 05921 }
| int ast_channel_supports_html | ( | struct ast_channel * | channel | ) |
Checks for HTML support on a channel
Returns 0 if channel does not support HTML or non-zero if it does
Definition at line 4350 of file channel.c.
References ast_channel_tech::send_html, and ast_channel::tech.
Referenced by dial_exec_full(), sendurl_exec(), and try_calling().
| 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 1164 of file channel.c.
References ast_clear_flag, and AST_FLAG_DEFER_DTMF.
Referenced by __adsi_transmit_messages(), find_cache(), and rpt_call().
01165 { 01166 if (chan) 01167 ast_clear_flag(chan, AST_FLAG_DEFER_DTMF); 01168 }
| void ast_channel_unregister | ( | const struct ast_channel_tech * | tech | ) |
Unregister channel driver.
Unregister a channel technology.
Definition at line 587 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::tech, and ast_channel_tech::type.
Referenced by __unload_module(), load_module(), and unload_module().
00588 { 00589 struct chanlist *chan; 00590 00591 ast_debug(1, "Unregistering channel type '%s'\n", tech->type); 00592 00593 AST_RWLIST_WRLOCK(&channels); 00594 00595 AST_LIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) { 00596 if (chan->tech == tech) { 00597 AST_LIST_REMOVE_CURRENT(list); 00598 ast_free(chan); 00599 ast_verb(2, "Unregistered channel type '%s'\n", tech->type); 00600 break; 00601 } 00602 } 00603 AST_LIST_TRAVERSE_SAFE_END; 00604 00605 AST_RWLIST_UNLOCK(&channels); 00606 }
| struct ast_channel* ast_channel_walk_locked | ( | const struct ast_channel * | prev | ) | [read] |
Browse channels in use.
Browse channels in use Browse the channels currently in use.
Definition at line 1278 of file channel.c.
References channel_find_locked().
Referenced by action_coreshowchannels(), action_status(), ast_complete_channels(), ast_var_channel_bridge(), ast_var_channel_types_table(), ast_var_channels_table(), conf_exec(), func_channels_read(), handle_chanlist(), handle_core_set_debug_channel(), and next_channel().
01279 { 01280 return channel_find_locked(prev, NULL, 0, NULL, NULL); 01281 }
| void ast_channels_init | ( | void | ) |
Provided by channel.c
Definition at line 5804 of file channel.c.
References ARRAY_LEN, ast_cli_register_multiple(), ast_plc_reload(), and cli_channel.
Referenced by main().
05805 { 05806 ast_cli_register_multiple(cli_channel, ARRAY_LEN(cli_channel)); 05807 05808 ast_plc_reload(); 05809 }
| struct ast_variable* ast_channeltype_list | ( | void | ) | [read] |
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::tech, ast_channel_tech::type, and var.
Referenced by ast_var_channel_types(), and ast_var_channel_types_table().
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 | ) |
Checks to see if a channel is needing hang up.
Check to see if a channel is needing hang up.
Definition at line 461 of file channel.c.
References ast_channel::_softhangup, AST_SOFTHANGUP_TIMEOUT, ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), 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_call(), ast_channel_bridge(), ast_check_hangup_locked(), 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_call_thread(), bridge_exec(), bridge_native_loop(), bridge_p2p_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(), feature_request_and_dial(), findmeexec(), handle_sendimage(), iax2_bridge(), launch_asyncagi(), lua_check_hangup(), ospfinished_exec(), pbx_builtin_incomplete(), pbx_exec(), read_exec(), readexten_exec(), rpt(), rpt_exec(), run_ras(), try_calling(), and wait_for_answer().
00462 { 00463 if (chan->_softhangup) /* yes if soft hangup flag set */ 00464 return 1; 00465 if (ast_tvzero(chan->whentohangup)) /* no if no hangup scheduled */ 00466 return 0; 00467 if (ast_tvdiff_ms(chan->whentohangup, ast_tvnow()) > 0) /* no if hangup time has not come yet. */ 00468 return 0; 00469 chan->_softhangup |= AST_SOFTHANGUP_TIMEOUT; /* record event */ 00470 return 1; 00471 }
| static int ast_check_hangup_locked | ( | struct ast_channel * | chan | ) | [static] |
Definition at line 473 of file channel.c.
References ast_channel_lock, ast_channel_unlock, and ast_check_hangup().
Referenced by ast_channel_bridge().
00474 { 00475 int res; 00476 ast_channel_lock(chan); 00477 res = ast_check_hangup(chan); 00478 ast_channel_unlock(chan); 00479 return res; 00480 }
| void ast_deactivate_generator | ( | struct ast_channel * | chan | ) |
Deactivate an active generator
Definition at line 2016 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(), 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().
02017 { 02018 ast_channel_lock(chan); 02019 if (chan->generatordata) { 02020 if (chan->generator && chan->generator->release) 02021 chan->generator->release(chan, chan->generatordata); 02022 chan->generatordata = NULL; 02023 chan->generator = NULL; 02024 ast_channel_set_fd(chan, AST_GENERATOR_FD, -1); 02025 ast_clear_flag(chan, AST_FLAG_WRITE_INT); 02026 ast_settimeout(chan, 0, NULL, NULL); 02027 } 02028 ast_channel_unlock(chan); 02029 }
| int ast_do_masquerade | ( | struct ast_channel * | original | ) |
Masquerade a channel.
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 4606 of file channel.c.
References ast_channel::_softhangup, ast_channel::_state, ast_channel::adsicpe, ast_channel::alertpipe, ast_app_group_update(), ast_bridged_channel(), ast_cause2str(), ast_channel_free(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_set_fd(), ast_channel_unlock, AST_CONTROL_SRCCHANGE, 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, errno, EVENT_FLAG_CALL, ast_channel::fdno, ast_channel::fds, ast_channel_tech::fixup, free_translation(), ast_channel_tech::hangup, ast_channel::hangupcause, ast_datastore::info, language, ast_channel::lock_dont_use, LOG_WARNING, manager_event, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, musicclass, name, ast_channel::nativeformats, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, report_new_callerid(), ast_channel::tech, ast_channel::tech_pvt, ast_channel::timingfd, ast_channel_tech::type, 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().
04607 { 04608 int x,i; 04609 int res=0; 04610 int origstate; 04611 struct ast_frame *current; 04612 const struct ast_channel_tech *t; 04613 void *t_pvt; 04614 struct ast_callerid tmpcid; 04615 struct ast_channel *clonechan = original->masq; 04616 struct ast_channel *bridged; 04617 struct ast_cdr *cdr; 04618 int rformat = original->readformat; 04619 int wformat = original->writeformat; 04620 char newn[AST_CHANNEL_NAME]; 04621 char orig[AST_CHANNEL_NAME]; 04622 char masqn[AST_CHANNEL_NAME]; 04623 char zombn[AST_CHANNEL_NAME]; 04624 04625 ast_debug(4, "Actually Masquerading %s(%d) into the structure of %s(%d)\n", 04626 clonechan->name, clonechan->_state, original->name, original->_state); 04627 04628 manager_event(EVENT_FLAG_CALL, "Masquerade", "Clone: %s\r\nCloneState: %s\r\nOriginal: %s\r\nOriginalState: %s\r\n", 04629 clonechan->name, ast_state2str(clonechan->_state), original->name, ast_state2str(original->_state)); 04630 04631 /* XXX This operation is a bit odd. We're essentially putting the guts of 04632 * the clone channel into the original channel. Start by killing off the 04633 * original channel's backend. While the features are nice, which is the 04634 * reason we're keeping it, it's still awesomely weird. XXX */ 04635 04636 /* We need the clone's lock, too */ 04637 ast_channel_lock(clonechan); 04638 04639 ast_debug(2, "Got clone lock for masquerade on '%s' at %p\n", clonechan->name, &clonechan->lock_dont_use); 04640 04641 /* Having remembered the original read/write formats, we turn off any translation on either 04642 one */ 04643 free_translation(clonechan); 04644 free_translation(original); 04645 04646 04647 /* Unlink the masquerade */ 04648 original->masq = NULL; 04649 clonechan->masqr = NULL; 04650 04651 /* Save the original name */ 04652 ast_copy_string(orig, original->name, sizeof(orig)); 04653 /* Save the new name */ 04654 ast_copy_string(newn, clonechan->name, sizeof(newn)); 04655 /* Create the masq name */ 04656 snprintf(masqn, sizeof(masqn), "%s<MASQ>", newn); 04657 04658 /* Copy the name from the clone channel */ 04659 ast_string_field_set(original, name, newn); 04660 04661 /* Mangle the name of the clone channel */ 04662 ast_string_field_set(clonechan, name, masqn); 04663 04664 /* Notify any managers of the change, first the masq then the other */ 04665 manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", newn, masqn, clonechan->uniqueid); 04666 manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", orig, newn, original->uniqueid); 04667 04668 /* Swap the technologies */ 04669 t = original->tech; 04670 original->tech = clonechan->tech; 04671 clonechan->tech = t; 04672 04673 /* Swap the cdrs */ 04674 cdr = original->cdr; 04675 original->cdr = clonechan->cdr; 04676 clonechan->cdr = cdr; 04677 04678 t_pvt = original->tech_pvt; 04679 original->tech_pvt = clonechan->tech_pvt; 04680 clonechan->tech_pvt = t_pvt; 04681 04682 /* Swap the alertpipes */ 04683 for (i = 0; i < 2; i++) { 04684 x = original->alertpipe[i]; 04685 original->alertpipe[i] = clonechan->alertpipe[i]; 04686 clonechan->alertpipe[i] = x; 04687 } 04688 04689 /* 04690 * Swap the readq's. The end result should be this: 04691 * 04692 * 1) All frames should be on the new (original) channel. 04693 * 2) Any frames that were already on the new channel before this 04694 * masquerade need to be at the end of the readq, after all of the 04695 * frames on the old (clone) channel. 04696 * 3) The alertpipe needs to get poked for every frame that was already 04697 * on the new channel, since we are now using the alert pipe from the 04698 * old (clone) channel. 04699 */ 04700 { 04701 AST_LIST_HEAD_NOLOCK(, ast_frame) tmp_readq; 04702 AST_LIST_HEAD_SET_NOLOCK(&tmp_readq, NULL); 04703 04704 AST_LIST_APPEND_LIST(&tmp_readq, &original->readq, frame_list); 04705 AST_LIST_APPEND_LIST(&original->readq, &clonechan->readq, frame_list); 04706 04707 while ((current = AST_LIST_REMOVE_HEAD(&tmp_readq, frame_list))) { 04708 AST_LIST_INSERT_TAIL(&original->readq, current, frame_list); 04709 if (original->alertpipe[1] > -1) { 04710 int poke = 0; 04711 04712 if (write(original->alertpipe[1], &poke, sizeof(poke)) < 0) { 04713 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); 04714 } 04715 } 04716 } 04717 } 04718 04719 /* Swap the raw formats */ 04720 x = original->rawreadformat; 04721 original->rawreadformat = clonechan->rawreadformat; 04722 clonechan->rawreadformat = x; 04723 x = original->rawwriteformat; 04724 original->rawwriteformat = clonechan->rawwriteformat; 04725 clonechan->rawwriteformat = x; 04726 04727 clonechan->_softhangup = AST_SOFTHANGUP_DEV; 04728 04729 /* And of course, so does our current state. Note we need not 04730 call ast_setstate since the event manager doesn't really consider 04731 these separate. We do this early so that the clone has the proper 04732 state of the original channel. */ 04733 origstate = original->_state; 04734 original->_state = clonechan->_state; 04735 clonechan->_state = origstate; 04736 04737 if (clonechan->tech->fixup){ 04738 res = clonechan->tech->fixup(original, clonechan); 04739 if (res) 04740 ast_log(LOG_WARNING, "Fixup failed on channel %s, strange things may happen.\n", clonechan->name); 04741 } 04742 04743 /* Start by disconnecting the original's physical side */ 04744 if (clonechan->tech->hangup) 04745 res = clonechan->tech->hangup(clonechan); 04746 if (res) { 04747 ast_log(LOG_WARNING, "Hangup failed! Strange things may happen!\n"); 04748 ast_channel_unlock(clonechan); 04749 return -1; 04750 } 04751 04752 snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig); 04753 /* Mangle the name of the clone channel */ 04754 ast_string_field_set(clonechan, name, zombn); 04755 manager_event(EVENT_FLAG_CALL, "Rename", "Channel: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", masqn, zombn, clonechan->uniqueid); 04756 04757 /* Update the type. */ 04758 t_pvt = original->monitor; 04759 original->monitor = clonechan->monitor; 04760 clonechan->monitor = t_pvt; 04761 04762 /* Keep the same language. */ 04763 ast_string_field_set(original, language, clonechan->language); 04764 /* Copy the FD's other than the generator fd */ 04765 for (x = 0; x < AST_MAX_FDS; x++) { 04766 if (x != AST_GENERATOR_FD) 04767 ast_channel_set_fd(original, x, clonechan->fds[x]); 04768 } 04769 04770 ast_app_group_update(clonechan, original); 04771 04772 /* Move data stores over */ 04773 if (AST_LIST_FIRST(&clonechan->datastores)) { 04774 struct ast_datastore *ds; 04775 /* We use a safe traversal here because some fixup routines actually 04776 * remove the datastore from the list and free them. 04777 */ 04778 AST_LIST_TRAVERSE_SAFE_BEGIN(&clonechan->datastores, ds, entry) { 04779 if (ds->info->chan_fixup) 04780 ds->info->chan_fixup(ds->data, clonechan, original); 04781 } 04782 AST_LIST_TRAVERSE_SAFE_END; 04783 AST_LIST_APPEND_LIST(&original->datastores, &clonechan->datastores, entry); 04784 } 04785 04786 clone_variables(original, clonechan); 04787 /* Presense of ADSI capable CPE follows clone */ 04788 original->adsicpe = clonechan->adsicpe; 04789 /* Bridge remains the same */ 04790 /* CDR fields remain the same */ 04791 /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */ 04792 /* Application and data remain the same */ 04793 /* Clone exception becomes real one, as with fdno */ 04794 ast_set_flag(original, ast_test_flag(clonechan, AST_FLAG_OUTGOING | AST_FLAG_EXCEPTION)); 04795 original->fdno = clonechan->fdno; 04796 /* Schedule context remains the same */ 04797 /* Stream stuff stays the same */ 04798 /* Keep the original state. The fixup code will need to work with it most likely */ 04799 04800 /* Just swap the whole structures, nevermind the allocations, they'll work themselves 04801 out. */ 04802 tmpcid = original->cid; 04803 original->cid = clonechan->cid; 04804 clonechan->cid = tmpcid; 04805 report_new_callerid(original); 04806 04807 /* Restore original timing file descriptor */ 04808 ast_channel_set_fd(original, AST_TIMING_FD, original->timingfd); 04809 04810 /* Our native formats are different now */ 04811 original->nativeformats = clonechan->nativeformats; 04812 04813 /* Context, extension, priority, app data, jump table, remain the same */ 04814 /* pvt switches. pbx stays the same, as does next */ 04815 04816 /* Set the write format */ 04817 ast_set_write_format(original, wformat); 04818 04819 /* Set the read format */ 04820 ast_set_read_format(original, rformat); 04821 04822 /* Copy the music class */ 04823 ast_string_field_set(original, musicclass, clonechan->musicclass); 04824 04825 ast_debug(1, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat); 04826 04827 /* Okay. Last thing is to let the channel driver know about all this mess, so he 04828 can fix up everything as best as possible */ 04829 if (original->tech->fixup) { 04830 res = original->tech->fixup(clonechan, original); 04831 if (res) { 04832 ast_log(LOG_WARNING, "Channel for type '%s' could not fixup channel %s\n", 04833 original->tech->type, original->name); 04834 ast_channel_unlock(clonechan); 04835 return -1; 04836 } 04837 } else 04838 ast_log(LOG_WARNING, "Channel type '%s' does not have a fixup routine (for %s)! Bad things may happen.\n", 04839 original->tech->type, original->name); 04840 04841 /* 04842 * If an indication is currently playing, maintain it on the channel 04843 * that is taking the place of original 04844 * 04845 * This is needed because the masquerade is swapping out in the internals 04846 * of this channel, and the new channel private data needs to be made 04847 * aware of the current visible indication (RINGING, CONGESTION, etc.) 04848 */ 04849 if (original->visible_indication) { 04850 ast_indicate(original, original->visible_indication); 04851 } 04852 04853 /* Now, at this point, the "clone" channel is totally F'd up. We mark it as 04854 a zombie so nothing tries to touch it. If it's already been marked as a 04855 zombie, then free it now (since it already is considered invalid). */ 04856 if (ast_test_flag(clonechan, AST_FLAG_ZOMBIE)) { 04857 ast_debug(1, "Destroying channel clone '%s'\n", clonechan->name); 04858 ast_channel_unlock(clonechan); 04859 manager_event(EVENT_FLAG_CALL, "Hangup", 04860 "Channel: %s\r\n" 04861 "Uniqueid: %s\r\n" 04862 "Cause: %d\r\n" 04863 "Cause-txt: %s\r\n", 04864 clonechan->name, 04865 clonechan->uniqueid, 04866 clonechan->hangupcause, 04867 ast_cause2str(clonechan->hangupcause) 04868 ); 04869 ast_channel_free(clonechan); 04870 } else { 04871 ast_debug(1, "Released clone lock on '%s'\n", clonechan->name); 04872 ast_set_flag(clonechan, AST_FLAG_ZOMBIE); 04873 ast_queue_frame(clonechan, &ast_null_frame); 04874 ast_channel_unlock(clonechan); 04875 } 04876 04877 /* Signal any blocker */ 04878 if (ast_test_flag(original, AST_FLAG_BLOCKING)) 04879 pthread_kill(original->blocker, SIGURG); 04880 ast_debug(1, "Done Masquerading %s (%d)\n", original->name, original->_state); 04881 04882 if ((bridged = ast_bridged_channel(original))) { 04883 ast_channel_lock(bridged); 04884 ast_indicate(bridged, AST_CONTROL_SRCCHANGE); 04885 ast_channel_unlock(bridged); 04886 } 04887 04888 ast_indicate(original, AST_CONTROL_SRCCHANGE); 04889 04890 return 0; 04891 }
| 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 4999 of file channel.c.
References ast_channel::_bridge, ast_channel::_softhangup, AST_BRIDGE_COMPLETE, AST_BRIDGE_DTMF_CHANNEL_0, AST_BRIDGE_DTMF_CHANNEL_1, AST_BRIDGE_IGNORE_SIGS, AST_BRIDGE_RETRY, AST_CONTROL_HOLD, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_debug, AST_FEATURE_WARNING_ACTIVE, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_indicate_data(), ast_jb_do_usecheck(), ast_jb_empty_and_reset(), ast_jb_get_and_deliver(), ast_jb_get_when_to_wakeup(), ast_jb_put(), ast_poll_channel_add(), ast_poll_channel_del(), ast_read(), ast_samp2tv(), ast_set_flag, AST_SOFTHANGUP_UNBRIDGE, ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), ast_waitfor_n(), ast_write(), ast_frame::data, ast_frame::datalen, f, ast_bridge_config::feature_timer, ast_bridge_config::flags, ast_frame::frametype, ast_channel::nativeformats, ast_bridge_config::nexteventts, ast_bridge_config::partialfeature_timer, ast_frame::ptr, ast_frame::subclass, ast_channel::tech_pvt, and ast_bridge_config::timelimit.
Referenced by ast_channel_bridge().
05002 { 05003 /* Copy voice back and forth between the two channels. */ 05004 struct ast_channel *cs[3]; 05005 struct ast_frame *f; 05006 enum ast_bridge_result res = AST_BRIDGE_COMPLETE; 05007 int o0nativeformats; 05008 int o1nativeformats; 05009 int watch_c0_dtmf; 05010 int watch_c1_dtmf; 05011 void *pvt0, *pvt1; 05012 /* Indicates whether a frame was queued into a jitterbuffer */ 05013 int frame_put_in_jb = 0; 05014 int jb_in_use; 05015 int to; 05016 05017 cs[0] = c0; 05018 cs[1] = c1; 05019 pvt0 = c0->tech_pvt; 05020 pvt1 = c1->tech_pvt; 05021 o0nativeformats = c0->nativeformats; 05022 o1nativeformats = c1->nativeformats; 05023 watch_c0_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_0; 05024 watch_c1_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_1; 05025 05026 /* Check the need of a jitterbuffer for each channel */ 05027 jb_in_use = ast_jb_do_usecheck(c0, c1); 05028 if (jb_in_use) 05029 ast_jb_empty_and_reset(c0, c1); 05030 05031 ast_poll_channel_add(c0, c1); 05032 05033 if (config->feature_timer > 0 && ast_tvzero(config->nexteventts)) { 05034 /* calculate when the bridge should possibly break 05035 * if a partial feature match timed out */ 05036 config->partialfeature_timer = ast_tvadd(ast_tvnow(), ast_samp2tv(config->feature_timer, 1000)); 05037 } else { 05038 memset(&config->partialfeature_timer, 0, sizeof(config->partialfeature_timer)); 05039 } 05040 05041 for (;;) { 05042 struct ast_channel *who, *other; 05043 05044 if ((c0->tech_pvt != pvt0) || (c1->tech_pvt != pvt1) || 05045 (o0nativeformats != c0->nativeformats) || 05046 (o1nativeformats != c1->nativeformats)) { 05047 /* Check for Masquerade, codec changes, etc */ 05048 res = AST_BRIDGE_RETRY; 05049 break; 05050 } 05051 if (bridge_end.tv_sec) { 05052 to = ast_tvdiff_ms(bridge_end, ast_tvnow()); 05053 if (to <= 0) { 05054 if (config->timelimit) { 05055 res = AST_BRIDGE_RETRY; 05056 /* generic bridge ending to play warning */ 05057 ast_set_flag(config, AST_FEATURE_WARNING_ACTIVE); 05058 } else { 05059 res = AST_BRIDGE_COMPLETE; 05060 } 05061 break; 05062 } 05063 } else { 05064 /* If a feature has been started and the bridge is configured to 05065 * to not break, leave the channel bridge when the feature timer 05066 * time has elapsed so the DTMF will be sent to the other side. 05067 */ 05068 if (!ast_tvzero(config->partialfeature_timer)) { 05069 int diff = ast_tvdiff_ms(config->partialfeature_timer, ast_tvnow()); 05070 if (diff <= 0) { 05071 res = AST_BRIDGE_RETRY; 05072 break; 05073 } 05074 } 05075 to = -1; 05076 } 05077 /* Calculate the appropriate max sleep interval - in general, this is the time, 05078 left to the closest jb delivery moment */ 05079 if (jb_in_use) 05080 to = ast_jb_get_when_to_wakeup(c0, c1, to); 05081 who = ast_waitfor_n(cs, 2, &to); 05082 if (!who) { 05083 /* No frame received within the specified timeout - check if we have to deliver now */ 05084 if (jb_in_use) 05085 ast_jb_get_and_deliver(c0, c1); 05086 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) { 05087 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 05088 c0->_softhangup = 0; 05089 if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 05090 c1->_softhangup = 0; 05091 c0->_bridge = c1; 05092 c1->_bridge = c0; 05093 } 05094 continue; 05095 } 05096 f = ast_read(who); 05097 if (!f) { 05098 *fo = NULL; 05099 *rc = who; 05100 ast_debug(1, "Didn't get a frame from channel: %s\n",who->name); 05101 break; 05102 } 05103 05104 other = (who == c0) ? c1 : c0; /* the 'other' channel */ 05105 /* Try add the frame info the who's bridged channel jitterbuff */ 05106 if (jb_in_use) 05107 frame_put_in_jb = !ast_jb_put(other, f); 05108 05109 if ((f->frametype == AST_FRAME_CONTROL) && !(config->flags & AST_BRIDGE_IGNORE_SIGS)) { 05110 int bridge_exit = 0; 05111 05112 switch (f->subclass) { 05113 case AST_CONTROL_HOLD: 05114 case AST_CONTROL_UNHOLD: 05115 case AST_CONTROL_VIDUPDATE: 05116 case AST_CONTROL_SRCUPDATE: 05117 case AST_CONTROL_SRCCHANGE: 05118 case AST_CONTROL_T38_PARAMETERS: 05119 ast_indicate_data(other, f->subclass, f->data.ptr, f->datalen); 05120 if (jb_in_use) { 05121 ast_jb_empty_and_reset(c0, c1); 05122 } 05123 break; 05124 default: 05125 *fo = f; 05126 *rc = who; 05127 bridge_exit = 1; 05128 ast_debug(1, "Got a FRAME_CONTROL (%d) frame on channel %s\n", f->subclass, who->name); 05129 break; 05130 } 05131 if (bridge_exit) 05132 break; 05133 } 05134 if ((f->frametype == AST_FRAME_VOICE) || 05135 (f->frametype == AST_FRAME_DTMF_BEGIN) || 05136 (f->frametype == AST_FRAME_DTMF) || 05137 (f->frametype == AST_FRAME_VIDEO) || 05138 (f->frametype == AST_FRAME_IMAGE) || 05139 (f->frametype == AST_FRAME_HTML) || 05140 (f->frametype == AST_FRAME_MODEM) || 05141 (f->frametype == AST_FRAME_TEXT)) { 05142 /* monitored dtmf causes exit from bridge */ 05143 int monitored_source = (who == c0) ? watch_c0_dtmf : watch_c1_dtmf; 05144 05145 if (monitored_source && 05146 (f->frametype == AST_FRAME_DTMF_END || 05147 f->frametype == AST_FRAME_DTMF_BEGIN)) { 05148 *fo = f; 05149 *rc = who; 05150 ast_debug(1, "Got DTMF %s on channel (%s)\n", 05151 f->frametype == AST_FRAME_DTMF_END ? "end" : "begin", 05152 who->name); 05153 05154 break; 05155 } 05156 /* Write immediately frames, not passed through jb */ 05157 if (!frame_put_in_jb) 05158 ast_write(other, f); 05159 05160 /* Check if we have to deliver now */ 05161 if (jb_in_use) 05162 ast_jb_get_and_deliver(c0, c1); 05163 } 05164 /* XXX do we want to pass on also frames not matched above ? */ 05165 ast_frfree(f); 05166 05167 #ifndef HAVE_EPOLL 05168 /* Swap who gets priority */ 05169 cs[2] = cs[0]; 05170 cs[0] = cs[1]; 05171 cs[1] = cs[2]; 05172 #endif 05173 } 05174 05175 ast_poll_channel_del(c0, c1); 05176 05177 return res; 05178 }
| struct ast_channel* ast_get_channel_by_exten_locked | ( | const char * | exten, | |
| const char * | context | |||
| ) | [read] |
Get channel by exten (and optionally context) and lock it.
Definition at line 1303 of file channel.c.
References channel_find_locked().
01304 { 01305 return channel_find_locked(NULL, NULL, 0, context, exten); 01306 }
| struct ast_channel* ast_get_channel_by_name_locked | ( | const char * | name | ) | [read] |
Get channel by name and lock it.
Get channel by name or uniqueid (locks channel).
Definition at line 1284 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(), 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_redirect(), handle_set_chanvar(), handle_show_chanvar(), handle_showchan(), handle_softhangup(), manager_park(), manager_play_dtmf(), park_call_full(), pbx_builtin_importvar(), shared_read(), shared_write(), start_monitor_action(), and stop_monitor_action().
01285 { 01286 return channel_find_locked(NULL, name, 0, NULL, NULL); 01287 }
| struct ast_channel* ast_get_channel_by_name_prefix_locked | ( | const char * | name, | |
| const int | namelen | |||
| ) | [read] |
Get channel by name prefix and lock it.
Get channel by name or uniqueid prefix (locks channel).
Definition at line 1290 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().
01291 { 01292 return channel_find_locked(NULL, name, namelen, NULL, NULL); 01293 }
| struct ast_channel_tech* ast_get_channel_tech | ( | const char * | name | ) | [read] |
Get handle to channel driver based on name.
Get a channel technology structure by name.
Definition at line 609 of file channel.c.
References AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, chanlist::tech, and ast_channel_tech::type.
Referenced by __ast_channel_alloc_ap(), _ast_device_state(), and ast_var_channel_types_table().
00610 { 00611 struct chanlist *chanls; 00612 const struct ast_channel_tech *ret = NULL; 00613 00614 AST_RWLIST_RDLOCK(&channels); 00615 00616 AST_LIST_TRAVERSE(&backends, chanls, list) { 00617 if (!strcasecmp(name, chanls->tech->type)) { 00618 ret = chanls->tech; 00619 break; 00620 } 00621 } 00622 00623 AST_RWLIST_UNLOCK(&channels); 00624 00625 return ret; 00626 }
| ast_group_t ast_get_group | ( | const char * | s | ) |
Definition at line 5712 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(), config_parse_variables(), func_channel_write(), process_dahdi(), and read_agent_config().
05713 { 05714 char *piece; 05715 char *c; 05716 int start=0, finish=0, x; 05717 ast_group_t group = 0; 05718 05719 if (ast_strlen_zero(s)) 05720 return 0; 05721 05722 c = ast_strdupa(s); 05723 05724 while ((piece = strsep(&c, ","))) { 05725 if (sscanf(piece, "%30d-%30d", &start, &finish) == 2) { 05726 /* Range */ 05727 } else if (sscanf(piece, "%30d", &start)) { 05728 /* Just one */ 05729 finish = start; 05730 } else { 05731 ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece); 05732 continue; 05733 } 05734 for (x = start; x <= finish; x++) { 05735 if ((x > 63) || (x < 0)) { 05736 ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x); 05737 } else 05738 group |= ((ast_group_t) 1 << x); 05739 } 05740 } 05741 return group; 05742 }
| int ast_hangup | ( | struct ast_channel * | chan | ) |
Hangup a channel.
Hang up a channel.
Definition at line 1750 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, 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_generator::release, S_OR, ast_channel::sched, sched_context_destroy(), ast_channel::stream, ast_channel::tech, and ast_channel::vstream.
Referenced by __ast_pbx_run(), __ast_request_and_dial(), __oh323_new(), action_bridge(), agent_hangup(), agent_read(), alsa_new(), answer_exec_run(), app_exec(), ast_async_goto(), ast_call_forward(), ast_dial_destroy(), ast_dial_hangup(), ast_iax2_new(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_pbx_run_app(), async_wait(), begin_dial_channel(), bridge_call_thread(), bridge_channel_thread(), bridge_exec(), build_conf(), builtin_atxfer(), chanavail_exec(), check_compat(), check_goto_on_transfer(), clear_caller(), conf_free(), conf_run(), connect_link(), console_new(), dahdi_handle_event(), dahdi_new(), destroy_conference_bridge(), dial_exec_full(), dial_transfer(), do_forward(), do_hang(), feature_attended_transfer(), feature_request_and_dial(), 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(), play_sound_file(), rpt(), rpt_call(), rpt_exec(), rpt_tele_thread(), sip_new(), sip_park(), sip_park_thread(), skinny_new(), skinny_ss(), ss_thread(), try_calling(), unistim_new(), usbradio_new(), wait_for_answer(), and wait_for_winner().
01751 { 01752 int res = 0; 01753 01754 /* Don't actually hang up a channel that will masquerade as someone else, or 01755 if someone is going to masquerade as us */ 01756 ast_channel_lock(chan); 01757 01758 if (chan->audiohooks) { 01759 ast_audiohook_detach_list(chan->audiohooks); 01760 chan->audiohooks = NULL; 01761 } 01762 01763 ast_autoservice_stop(chan); 01764 01765 if (chan->masq) { 01766 if (ast_do_masquerade(chan)) 01767 ast_log(LOG_WARNING, "Failed to perform masquerade\n"); 01768 } 01769 01770 if (chan->masq) { 01771 ast_log(LOG_WARNING, "%s getting hung up, but someone is trying to masq into us?!?\n", chan->name); 01772 ast_channel_unlock(chan); 01773 return 0; 01774 } 01775 /* If this channel is one which will be masqueraded into something, 01776 mark it as a zombie already, so we know to free it later */ 01777 if (chan->masqr) { 01778 ast_set_flag(chan, AST_FLAG_ZOMBIE); 01779 ast_channel_unlock(chan); 01780 return 0; 01781 } 01782 ast_channel_unlock(chan); 01783 01784 AST_RWLIST_WRLOCK(&channels); 01785 if (!AST_RWLIST_REMOVE(&channels, chan, chan_list)) { 01786 ast_log(LOG_ERROR, "Unable to find channel in list to free. Assuming it has already been done.\n"); 01787 } 01788 ast_clear_flag(chan, AST_FLAG_IN_CHANNEL_LIST); 01789 AST_RWLIST_UNLOCK(&channels); 01790 01791 ast_channel_lock(chan); 01792 free_translation(chan); 01793 /* Close audio stream */ 01794 if (chan->stream) { 01795 ast_closestream(chan->stream); 01796 chan->stream = NULL; 01797 } 01798 /* Close video stream */ 01799 if (chan->vstream) { 01800 ast_closestream(chan->vstream); 01801 chan->vstream = NULL; 01802 } 01803 if (chan->sched) { 01804 sched_context_destroy(chan->sched); 01805 chan->sched = NULL; 01806 } 01807 01808 if (chan->generatordata) /* Clear any tone stuff remaining */ 01809 if (chan->generator && chan->generator->release) 01810 chan->generator->release(chan, chan->generatordata); 01811 chan->generatordata = NULL; 01812 chan->generator = NULL; 01813 if (ast_test_flag(chan, AST_FLAG_BLOCKING)) { 01814 ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd " 01815 "is blocked by thread %ld in procedure %s! Expect a failure\n", 01816 (long)pthread_self(), chan->name, (long)chan->blocker, chan->blockproc); 01817 ast_assert(ast_test_flag(chan, AST_FLAG_BLOCKING) == 0); 01818 } 01819 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE)) { 01820 ast_debug(1, "Hanging up channel '%s'\n", chan->name); 01821 if (chan->tech->hangup) 01822 res = chan->tech->hangup(chan); 01823 } else { 01824 ast_debug(1, "Hanging up zombie '%s'\n", chan->name); 01825 } 01826 01827 ast_channel_unlock(chan); 01828 manager_event(EVENT_FLAG_CALL, "Hangup", 01829 "Channel: %s\r\n" 01830 "Uniqueid: %s\r\n" 01831 "CallerIDNum: %s\r\n" 01832 "CallerIDName: %s\r\n" 01833 "Cause: %d\r\n" 01834 "Cause-txt: %s\r\n", 01835 chan->name, 01836 chan->uniqueid, 01837 S_OR(chan->cid.cid_num, "<unknown>"), 01838 S_OR(chan->cid.cid_name, "<unknown>"), 01839 chan->hangupcause, 01840 ast_cause2str(chan->hangupcause) 01841 ); 01842 01843 if (chan->cdr && !ast_test_flag(chan->cdr, AST_CDR_FLAG_BRIDGED) && 01844 !ast_test_flag(chan->cdr, AST_CDR_FLAG_POST_DISABLED) && 01845 (chan->cdr->disposition != AST_CDR_NULL || ast_test_flag(chan->cdr, AST_CDR_FLAG_DIALED))) { 01846 ast_channel_lock(chan); 01847 01848 ast_cdr_end(chan->cdr); 01849 ast_cdr_detach(chan->cdr); 01850 chan->cdr = NULL; 01851 ast_channel_unlock(chan); 01852 } 01853 01854 ast_channel_free(chan); 01855 01856 return res; 01857 }
| 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 3189 of file channel.c.
References ast_indicate_data().
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_raw_answer(), attempt_transfer(), builtin_atxfer(), builtin_blindtransfer(), cli_console_answer(), conf_run(), console_call(), dial_exec_full(), disa_exec(), do_forward(), feature_request_and_dial(), finishup(), function_remote(), handle_callforward_button(), handle_frame(), handle_recordfile(), manage_parkinglot(), mgcp_ss(), monitor_dial(), oss_call(), park_call_full(), park_exec_full(), pbx_builtin_busy(), pbx_builtin_congestion(), pbx_builtin_proceeding(), pbx_builtin_progress(), pbx_builtin_ringing(), pbx_builtin_waitexten(), queue_exec(), record_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(), try_calling(), and wait_for_answer().
03190 { 03191 return ast_indicate_data(chan, condition, NULL, 0); 03192 }
| 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 3230 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, ast_tone_zone_sound_unref(), ast_tone_zone_sound::data, ast_channel_tech::indicate, is_visible_indication(), LOG_WARNING, ast_channel::tech, ast_channel::visible_indication, and ast_channel::zone.
Referenced by agent_hangup(), ast_bridge_call(), ast_generic_bridge(), ast_indicate(), bridge_native_loop(), bridge_p2p_loop(), login_exec(), manage_parkinglot(), park_call_full(), pbx_builtin_waitexten(), transmit_audio(), transmit_t38(), and wait_for_answer().
03232 { 03233 /* By using an enum, we'll get compiler warnings for values not handled 03234 * in switch statements. */ 03235 enum ast_control_frame_type condition = _condition; 03236 struct ast_tone_zone_sound *ts = NULL; 03237 int res = -1; 03238 03239 ast_channel_lock(chan); 03240 03241 /* Don't bother if the channel is about to go away, anyway. */ 03242 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 03243 ast_channel_unlock(chan); 03244 return -1; 03245 } 03246 03247 if (chan->tech->indicate) { 03248 /* See if the channel driver can handle this condition. */ 03249 res = chan->tech->indicate(chan, condition, data, datalen); 03250 } 03251 03252 ast_channel_unlock(chan); 03253 03254 if (!res) { 03255 /* The channel driver successfully handled this indication */ 03256 if (is_visible_indication(condition)) { 03257 chan->visible_indication = condition; 03258 } 03259 return 0; 03260 } 03261 03262 /* The channel driver does not support this indication, let's fake 03263 * it by doing our own tone generation if applicable. */ 03264 03265 /*!\note If we compare the enumeration type, which does not have any 03266 * negative constants, the compiler may optimize this code away. 03267 * Therefore, we must perform an integer comparison here. */ 03268 if (_condition < 0) { 03269 /* Stop any tones that are playing */ 03270 ast_playtones_stop(chan); 03271 return 0; 03272 } 03273 03274 /* Handle conditions that we have tones for. */ 03275 switch (condition) { 03276 case _XXX_AST_CONTROL_T38: 03277 /* deprecated T.38 control frame */ 03278 return -1; 03279 case AST_CONTROL_T38_PARAMETERS: 03280 /* there is no way to provide 'default' behavior for these 03281 * control frames, so we need to return failure, but there 03282 * is also no value in the log message below being emitted 03283 * since failure to handle these frames is not an 'error' 03284 * so just return right now. in addition, we want to return 03285 * whatever value the channel driver returned, in case it 03286 * has some meaning.*/ 03287 return res; 03288 case AST_CONTROL_RINGING: 03289 ts = ast_get_indication_tone(chan->zone, "ring"); 03290 /* It is common practice for channel drivers to return -1 if trying 03291 * to indicate ringing on a channel which is up. The idea is to let the 03292 * core generate the ringing inband. However, we don't want the 03293 * warning message about not being able to handle the specific indication 03294 * to print nor do we want ast_indicate_data to return an "error" for this 03295 * condition 03296 */ 03297 if (chan->_state == AST_STATE_UP) { 03298 res = 0; 03299 } 03300 break; 03301 case AST_CONTROL_BUSY: 03302 ts = ast_get_indication_tone(chan->zone, "busy"); 03303 break; 03304 case AST_CONTROL_CONGESTION: 03305 ts = ast_get_indication_tone(chan->zone, "congestion"); 03306 break; 03307 case AST_CONTROL_PROGRESS: 03308 case AST_CONTROL_PROCEEDING: 03309 case AST_CONTROL_VIDUPDATE: 03310 case AST_CONTROL_SRCUPDATE: 03311 case AST_CONTROL_SRCCHANGE: 03312 case AST_CONTROL_RADIO_KEY: 03313 case AST_CONTROL_RADIO_UNKEY: 03314 case AST_CONTROL_OPTION: 03315 case AST_CONTROL_WINK: 03316 case AST_CONTROL_FLASH: 03317 case AST_CONTROL_OFFHOOK: 03318 case AST_CONTROL_TAKEOFFHOOK: 03319 case AST_CONTROL_ANSWER: 03320 case AST_CONTROL_HANGUP: 03321 case AST_CONTROL_RING: 03322 case AST_CONTROL_HOLD: 03323 case AST_CONTROL_UNHOLD: 03324 /* Nothing left to do for these. */ 03325 res = 0; 03326 break; 03327 } 03328 03329 if (ts) { 03330 /* We have a tone to play, yay. */ 03331 ast_debug(1, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition); 03332 ast_playtones_start(chan, 0, ts->data, 1); 03333 ts = ast_tone_zone_sound_unref(ts); 03334 res = 0; 03335 chan->visible_indication = condition; 03336 } 03337 03338 if (res) { 03339 /* not handled */ 03340 ast_log(LOG_WARNING, "Unable to handle indication %d for '%s'\n", condition, chan->name); 03341 } 03342 03343 return res; 03344 }
| 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 5748 of file channel.c.
References ast_moh_cleanup_ptr, ast_moh_start_ptr, and ast_moh_stop_ptr.
Referenced by load_module(), and reload().
05751 { 05752 ast_moh_start_ptr = start_ptr; 05753 ast_moh_stop_ptr = stop_ptr; 05754 ast_moh_cleanup_ptr = cleanup_ptr; 05755 }
| int ast_internal_timing_enabled | ( | struct ast_channel * | chan | ) |
Check if the channel can run in internal timing mode.
| chan | The channel to check |
This function will return 1 if internal timing is enabled and the timing device is available.
Definition at line 3174 of file channel.c.
References ast_opt_internal_timing, and ast_channel::timingfd.
Referenced by add_sdp(), and ast_read_generator_actions().
03175 { 03176 return (ast_opt_internal_timing && chan->timingfd > -1); 03177 }
| int ast_is_deferrable_frame | ( | const struct ast_frame * | frame | ) |
Should we keep this frame for later?
There are functions such as ast_safe_sleep which will service a channel to ensure that it does not have a large backlog of queued frames. When this happens, we want to hold on to specific frame types and just drop others. This function will tell if the frame we just read should be held onto.
| frame | The frame we just read |
| 1 | frame should be kept | |
| 0 | frame should be dropped |
Definition at line 1333 of file channel.c.
References 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, and ast_frame::frametype.
Referenced by ast_safe_sleep_conditional(), and autoservice_run().
01334 { 01335 /* Do not add a default entry in this switch statement. Each new 01336 * frame type should be addressed directly as to whether it should 01337 * be queued up or not. 01338 */ 01339 switch (frame->frametype) { 01340 case AST_FRAME_DTMF_END: 01341 case AST_FRAME_CONTROL: 01342 case AST_FRAME_TEXT: 01343 case AST_FRAME_IMAGE: 01344 case AST_FRAME_HTML: 01345 return 1; 01346 01347 case AST_FRAME_DTMF_BEGIN: 01348 case AST_FRAME_VOICE: 01349 case AST_FRAME_VIDEO: 01350 case AST_FRAME_NULL: 01351 case AST_FRAME_IAX: 01352 case AST_FRAME_CNG: 01353 case AST_FRAME_MODEM: 01354 return 0; 01355 } 01356 return 0; 01357 }
| void ast_moh_cleanup | ( | struct ast_channel * | chan | ) |
Definition at line 5782 of file channel.c.
References ast_moh_cleanup_ptr.
Referenced by ast_channel_free().
05783 { 05784 if (ast_moh_cleanup_ptr) 05785 ast_moh_cleanup_ptr(chan); 05786 }
| 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 5765 of file channel.c.
References ast_moh_start_ptr, and ast_verb.
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(), leave_conference_bridge(), local_indicate(), menu_callback(), mgcp_indicate(), misdn_indication(), moh_handle_digit(), monitor_dial(), oh323_indicate(), oss_indicate(), phone_indicate(), play_moh_exec(), post_join_marked(), post_join_unmarked(), 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().
05766 { 05767 if (ast_moh_start_ptr) 05768 return ast_moh_start_ptr(chan, mclass, interpclass); 05769 05770 ast_verb(3, "Music class %s requested but no musiconhold loaded.\n", mclass ? mclass : (interpclass ? interpclass : "default")); 05771 05772 return 0; 05773 }
| 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 5776 of file channel.c.
References ast_moh_stop_ptr.
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(), menu_callback(), mgcp_indicate(), misdn_indication(), moh_handle_digit(), monitor_dial(), oh323_indicate(), oss_indicate(), phone_indicate(), play_moh_exec(), post_join_marked(), post_join_unmarked(), queue_exec(), retrydial_exec(), say_periodic_announcement(), say_position(), sip_indicate(), skinny_indicate(), stop_moh_exec(), try_calling(), unistim_hangup(), unistim_indicate(), usbradio_indicate(), and wait_moh_exec().
05777 { 05778 if (ast_moh_stop_ptr) 05779 ast_moh_stop_ptr(chan); 05780 }
| int ast_plc_reload | ( | void | ) |
Reload genericplc configuration value from codecs.conf.
Implementation is in main/channel.c
Definition at line 5788 of file channel.c.
References ast_config_destroy(), ast_config_load2(), AST_OPT_FLAG_GENERIC_PLC, ast_options, ast_set2_flag, ast_true(), ast_variable_browse(), CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, ast_variable::name, ast_variable::next, ast_variable::value, and var.
Referenced by ast_channels_init().
05789 { 05790 struct ast_variable *var; 05791 struct ast_flags config_flags = { 0 }; 05792 struct ast_config *cfg = ast_config_load2("codecs.conf", "channel", config_flags); 05793 if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) 05794 return 0; 05795 for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) { 05796 if (!strcasecmp(var->name, "genericplc")) { 05797 ast_set2_flag(&ast_options, ast_true(var->value), AST_OPT_FLAG_GENERIC_PLC); 05798 } 05799 } 05800 ast_config_destroy(cfg); 05801 return 0; 05802 }
| void ast_poll_channel_add | ( | struct ast_channel * | chan0, | |
| struct ast_channel * | chan1 | |||
| ) |
Add a channel to an optimized waitfor
Definition at line 1670 of file channel.c.
References AST_MAX_FDS, and ast_channel::fds.
Referenced by ast_generic_bridge(), begin_dial_channel(), bridge_native_loop(), bridge_p2p_loop(), feature_request_and_dial(), and wait_for_answer().
01671 { 01672 #ifdef HAVE_EPOLL 01673 struct epoll_event ev; 01674 int i = 0; 01675 01676 if (chan0->epfd == -1) 01677 return; 01678 01679 /* Iterate through the file descriptors on chan1, adding them to chan0 */ 01680 for (i = 0; i < AST_MAX_FDS; i++) { 01681 if (chan1->fds[i] == -1) 01682 continue; 01683 ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP; 01684 ev.data.ptr = chan1->epfd_data[i]; 01685 epoll_ctl(chan0->epfd, EPOLL_CTL_ADD, chan1->fds[i], &ev); 01686 } 01687 01688 #endif 01689 return; 01690 }
| void ast_poll_channel_del | ( | struct ast_channel * | chan0, | |
| struct ast_channel * | chan1 | |||
| ) |
Delete a channel from an optimized waitfor
Definition at line 1693 of file channel.c.
References AST_MAX_FDS, and ast_channel::fds.
Referenced by ast_generic_bridge(), bridge_native_loop(), bridge_p2p_loop(), feature_request_and_dial(), monitor_dial(), and wait_for_answer().
01694 { 01695 #ifdef HAVE_EPOLL 01696 struct epoll_event ev; 01697 int i = 0; 01698 01699 if (chan0->epfd == -1) 01700 return; 01701 01702 for (i = 0; i < AST_MAX_FDS; i++) { 01703 if (chan1->fds[i] == -1) 01704 continue; 01705 epoll_ctl(chan0->epfd, EPOLL_CTL_DEL, chan1->fds[i], &ev); 01706 } 01707 01708 #endif 01709 return; 01710 }
| char* ast_print_group | ( | char * | buf, | |
| int | buflen, | |||
| ast_group_t | group | |||
| ) |
Print call group and pickup group ---.
print call- and pickup groups into buffer
Definition at line 5812 of file channel.c.
Referenced by _sip_show_peer(), _skinny_show_line(), func_channel_read(), function_sippeer(), misdn_cfg_get_config_string(), print_group(), read_config(), and serialize_showchan().
05813 { 05814 unsigned int i; 05815 int first = 1; 05816 char num[3]; 05817 05818 buf[0] = '\0'; 05819 05820 if (!group) /* Return empty string if no group */ 05821 return buf; 05822 05823 for (i = 0; i <= 63; i++) { /* Max group is 63 */ 05824 if (group & ((ast_group_t) 1 << i)) { 05825 if (!first) { 05826 strncat(buf, ", ", buflen - strlen(buf) - 1); 05827 } else { 05828 first = 0; 05829 } 05830 snprintf(num, sizeof(num), "%u", i); 05831 strncat(buf, num, buflen - strlen(buf) - 1); 05832 } 05833 } 05834 return buf; 05835 }
| int ast_prod | ( | struct ast_channel * | chan | ) |
Send empty audio to prime a channel driver.
Definition at line 3465 of file channel.c.
References ast_channel::_state, ast_debug, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), AST_STATE_UP, ast_write(), ast_frame::data, LOG_WARNING, ast_frame::ptr, ast_channel::rawwriteformat, ast_frame::src, and ast_frame::subclass.
Referenced by ast_activate_generator().
03466 { 03467 struct ast_frame a = { AST_FRAME_VOICE }; 03468 char nothing[128]; 03469 03470 /* Send an empty audio frame to get things moving */ 03471 if (chan->_state != AST_STATE_UP) { 03472 ast_debug(1, "Prodding channel '%s'\n", chan->name); 03473 a.subclass = chan->rawwriteformat; 03474 a.data.ptr = nothing + AST_FRIENDLY_OFFSET; 03475 a.src = "ast_prod"; /* this better match check in ast_write */ 03476 if (ast_write(chan, &a)) 03477 ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", chan->name); 03478 } 03479 return 0; 03480 }
| int ast_queue_control | ( | struct ast_channel * | chan, | |
| enum ast_control_frame_type | control | |||
| ) |
Queue a control frame.
Queue a control frame with payload.
Definition at line 1129 of file channel.c.
References AST_FRAME_CONTROL, ast_queue_frame(), and ast_frame::subclass.
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().
01130 { 01131 struct ast_frame f = { AST_FRAME_CONTROL, }; 01132 01133 f.subclass = control; 01134 01135 return ast_queue_frame(chan, &f); 01136 }
| 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 supplied payload data is copied into the frame, so the caller's copy is not modified nor freed, and the resulting frame will retain a copy of the data even if the caller frees their local copy.
Definition at line 1139 of file channel.c.
References AST_FRAME_CONTROL, ast_queue_frame(), ast_frame::data, ast_frame::datalen, ast_frame::ptr, and ast_frame::subclass.
Referenced by change_t38_state(), dahdi_handle_event(), dahdi_hangup(), iax2_queue_control_data(), interpret_t38_parameters(), process_sdp(), and skinny_hold().
01141 { 01142 struct ast_frame f = { AST_FRAME_CONTROL, }; 01143 01144 f.subclass = control; 01145 f.data.ptr = (void *) data; 01146 f.datalen = datalen; 01147 01148 return ast_queue_frame(chan, &f); 01149 }
| 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 1086 of file channel.c.
References __ast_queue_frame().
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_dsp_process(), ast_queue_control(), ast_queue_control_data(), ast_queue_hangup(), ast_queue_hangup_with_cause(), ast_softhangup_nolock(), bridge_write(), 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(), 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().
01087 { 01088 return __ast_queue_frame(chan, fin, 0, NULL); 01089 }
| 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 1091 of file channel.c.
References __ast_queue_frame().
Referenced by __ast_answer(), __ast_read(), ast_autoservice_stop(), and ast_safe_sleep_conditional().
01092 { 01093 return __ast_queue_frame(chan, fin, 1, NULL); 01094 }
| int ast_queue_hangup | ( | struct ast_channel * | chan | ) |
Queue a hangup frame for channel.
Queue a hangup frame.
Definition at line 1097 of file channel.c.
References ast_channel::_softhangup, ast_channel_trylock, ast_channel_unlock, AST_CONTROL_HANGUP, AST_FRAME_CONTROL, ast_queue_frame(), and AST_SOFTHANGUP_DEV.
Referenced by bridge_queue_hangup(), 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().
01098 { 01099 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; 01100 /* Yeah, let's not change a lock-critical value without locking */ 01101 if (!ast_channel_trylock(chan)) { 01102 chan->_softhangup |= AST_SOFTHANGUP_DEV; 01103 ast_channel_unlock(chan); 01104 } 01105 return ast_queue_frame(chan, &f); 01106 }
| int ast_queue_hangup_with_cause | ( | struct ast_channel * | chan, | |
| int | cause | |||
| ) |
Queue a hangup frame for channel.
Queue a hangup frame with hangupcause set.
Definition at line 1109 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, ast_frame::data, ast_channel::hangupcause, and ast_frame::uint32.
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(), retrans_pkt(), and TransferCallStep1().
01110 { 01111 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; 01112 01113 if (cause >= 0) 01114 f.data.uint32 = cause; 01115 01116 /* Yeah, let's not change a lock-critical value without locking */ 01117 if (!ast_channel_trylock(chan)) { 01118 chan->_softhangup |= AST_SOFTHANGUP_DEV; 01119 if (cause < 0) 01120 f.data.uint32 = chan->hangupcause; 01121 01122 ast_channel_unlock(chan); 01123 } 01124 01125 return ast_queue_frame(chan, &f); 01126 }
| 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' |
This function answers a channel and handles all necessary call setup functions.
| 0 | on success | |
| non-zero | on failure |
Definition at line 1859 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, ast_channel::tech, and ast_channel::visible_indication.
Referenced by __ast_answer(), and ast_bridge_call().
01860 { 01861 int res = 0; 01862 01863 ast_channel_lock(chan); 01864 01865 /* You can't answer an outbound call */ 01866 if (ast_test_flag(chan, AST_FLAG_OUTGOING)) { 01867 ast_channel_unlock(chan); 01868 return 0; 01869 } 01870 01871 /* Stop if we're a zombie or need a soft hangup */ 01872 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 01873 ast_channel_unlock(chan); 01874 return -1; 01875 } 01876 01877 ast_channel_unlock(chan); 01878 01879 switch (chan->_state) { 01880 case AST_STATE_RINGING: 01881 case AST_STATE_RING: 01882 ast_channel_lock(chan); 01883 if (chan->tech->answer) { 01884 res = chan->tech->answer(chan); 01885 } 01886 ast_setstate(chan, AST_STATE_UP); 01887 if (cdr_answer) { 01888 ast_cdr_answer(chan->cdr); 01889 } 01890 ast_channel_unlock(chan); 01891 break; 01892 case AST_STATE_UP: 01893 /* Calling ast_cdr_answer when it it has previously been called 01894 * is essentially a no-op, so it is safe. 01895 */ 01896 if (cdr_answer) { 01897 ast_cdr_answer(chan->cdr); 01898 } 01899 break; 01900 default: 01901 break; 01902 } 01903 01904 ast_indicate(chan, -1); 01905 chan->visible_indication = 0; 01906 01907 return res; 01908 }
| struct ast_frame* ast_read | ( | struct ast_channel * | chan | ) | [read] |
Reads a frame.
| chan | channel to read a frame from |
Definition at line 3179 of file channel.c.
References __ast_read().
Referenced by __adsi_transmit_messages(), __ast_answer(), __ast_play_and_record(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), agent_read(), ast_bridge_handle_trip(), ast_generic_bridge(), 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_waiting(), echo_exec(), eivr_comm(), feature_request_and_dial(), find_cache(), handle_recordfile(), handle_speechrecognize(), iax2_bridge(), iax_park_thread(), ices_exec(), isAnsweringMachine(), jack_exec(), launch_asyncagi(), manage_parkinglot(), masq_park_call(), measurenoise(), misdn_bridge(), monitor_dial(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), record_exec(), recordthread(), rpt(), rpt_exec(), 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().
03180 { 03181 return __ast_read(chan, 0); 03182 }
| static void ast_read_generator_actions | ( | struct ast_channel * | chan, | |
| struct ast_frame * | f | |||
| ) | [static] |
Definition at line 2593 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(), ast_frame::datalen, ast_frame::frametype, ast_generator::generate, ast_channel::generator, generator_force(), ast_channel::generatordata, ast_frame::samples, ast_frame::subclass, ast_channel::timingfd, ast_channel::timingfunc, and ast_channel::writeformat.
Referenced by __ast_read().
02594 { 02595 if (chan->generator && chan->generator->generate && chan->generatordata && !ast_internal_timing_enabled(chan)) { 02596 void *tmp = chan->generatordata; 02597 int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples) = chan->generator->generate; 02598 int res; 02599 int samples; 02600 02601 if (chan->timingfunc) { 02602 ast_debug(1, "Generator got voice, switching to phase locked mode\n"); 02603 ast_settimeout(chan, 0, NULL, NULL); 02604 } 02605 02606 chan->generatordata = NULL; /* reset, to let writes go through */ 02607 02608 if (f->subclass != chan->writeformat) { 02609 float factor; 02610 factor = ((float) ast_format_rate(chan->writeformat)) / ((float) ast_format_rate(f->subclass)); 02611 samples = (int) ( ((float) f->samples) * factor ); 02612 } else { 02613 samples = f->samples; 02614 } 02615 02616 /* This unlock is here based on two assumptions that hold true at this point in the 02617 * code. 1) this function is only called from within __ast_read() and 2) all generators 02618 * call ast_write() in their generate callback. 02619 * 02620 * The reason this is added is so that when ast_write is called, the lock that occurs 02621 * there will not recursively lock the channel. Doing this will cause intended deadlock 02622 * avoidance not to work in deeper functions 02623 */ 02624 ast_channel_unlock(chan); 02625 res = generate(chan, tmp, f->datalen, samples); 02626 ast_channel_lock(chan); 02627 chan->generatordata = tmp; 02628 if (res) { 02629 ast_debug(1, "Auto-deactivating generator\n"); 02630 ast_deactivate_generator(chan); 02631 } 02632 02633 } else if (f->frametype == AST_FRAME_CNG) { 02634 if (chan->generator && !chan->timingfunc && (chan->timingfd > -1)) { 02635 ast_debug(1, "Generator got CNG, switching to timed mode\n"); 02636 ast_settimeout(chan, 50, generator_force, chan); 02637 } 02638 } 02639 }
| struct ast_frame* ast_read_noaudio | ( | struct ast_channel * | chan | ) | [read] |
Reads a frame, returning AST_FRAME_NULL frame if audio.
| chan | channel to read a frame from |
Definition at line 3184 of file channel.c.
References __ast_read().
Referenced by ast_bridge_handle_trip(), and conf_run().
03185 { 03186 return __ast_read(chan, 1); 03187 }
| 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 4297 of file channel.c.
References ast_readstring_full().
Referenced by __adsi_transmit_messages(), _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().
04298 { 04299 return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1); 04300 }
| 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 4302 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().
04303 { 04304 int pos = 0; /* index in the buffer where we accumulate digits */ 04305 int to = ftimeout; 04306 04307 /* Stop if we're a zombie or need a soft hangup */ 04308 if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c)) 04309 return -1; 04310 if (!len) 04311 return -1; 04312 for (;;) { 04313 int d; 04314 if (c->stream) { 04315 d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd); 04316 ast_stopstream(c); 04317 usleep(1000); 04318 if (!d) 04319 d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); 04320 } else { 04321 d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); 04322 } 04323 if (d < 0) 04324 return AST_GETDATA_FAILED; 04325 if (d == 0) { 04326 s[pos] = '\0'; 04327 return AST_GETDATA_TIMEOUT; 04328 } 04329 if (d == 1) { 04330 s[pos] = '\0'; 04331 return AST_GETDATA_INTERRUPTED; 04332 } 04333 if (strchr(enders, d) && (pos == 0)) { 04334 s[pos] = '\0'; 04335 return AST_GETDATA_EMPTY_END_TERMINATED; 04336 } 04337 if (!strchr(enders, d)) { 04338 s[pos++] = d; 04339 } 04340 if (strchr(enders, d) || (pos >= len)) { 04341 s[pos] = '\0'; 04342 return AST_GETDATA_COMPLETE; 04343 } 04344 to = timeout; 04345 } 04346 /* Never reached */ 04347 return 0; 04348 }
| 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 3346 of file channel.c.
References ast_free, and ast_recvtext().
Referenced by handle_recvchar().
03347 { 03348 int c; 03349 char *buf = ast_recvtext(chan, timeout); 03350 if (buf == NULL) 03351 return -1; /* error or timeout */ 03352 c = *(unsigned char *)buf; 03353 ast_free(buf); 03354 return c; 03355 }
| 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 3357 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(), ast_frame::data, ast_frame::datalen, f, ast_frame::frametype, ast_frame::ptr, and ast_frame::subclass.
Referenced by ast_recvchar(), and handle_recvtext().
03358 { 03359 int res, done = 0; 03360 char *buf = NULL; 03361 03362 while (!done) { 03363 struct ast_frame *f; 03364 if (ast_check_hangup(chan)) 03365 break; 03366 res = ast_waitfor(chan, timeout); 03367 if (res <= 0) /* timeout or error */ 03368 break; 03369 timeout = res; /* update timeout */ 03370 f = ast_read(chan); 03371 if (f == NULL) 03372 break; /* no frame */ 03373 if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) 03374 done = 1; /* force a break */ 03375 else if (f->frametype == AST_FRAME_TEXT) { /* what we want */ 03376 buf = ast_strndup((char *) f->data.ptr, f->datalen); /* dup and break */ 03377 done = 1; 03378 } 03379 ast_frfree(f); 03380 } 03381 return buf; 03382 }
| struct ast_channel* ast_request | ( | const char * | type, | |
| int | format, | |||
| void * | data, | |||
| int * | status | |||
| ) | [read] |
Requests a channel.
| type | type of channel to request | |
| format | requested channel format (codec) | |
| data | data to pass to the channel requester | |
| status | status |
Request a channel of a given type, with data as optional information used by the low level module
| NULL | failure | |
| non-NULL | channel on success |
Definition at line 4196 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(), ast_channel_tech::capabilities, capabilities, LOG_WARNING, ast_channel_tech::requester, chanlist::tech, and ast_channel_tech::type.
Referenced by __ast_request_and_dial(), agent_request(), ast_call_forward(), attempt_reconnect(), begin_dial_channel(), build_conf(), chanavail_exec(), conf_run(), connect_link(), dial_exec_full(), dial_transfer(), do_forward(), feature_request_and_dial(), findmeexec(), play_sound_file(), ring_entry(), rpt(), rpt_call(), rpt_exec(), rpt_tele_thread(), and wait_for_answer().
04197 { 04198 struct chanlist *chan; 04199 struct ast_channel *c; 04200 int capabilities; 04201 int fmt; 04202 int res; 04203 int foo; 04204 int videoformat = format & AST_FORMAT_VIDEO_MASK; 04205 int textformat = format & AST_FORMAT_TEXT_MASK; 04206 04207 if (!cause) 04208 cause = &foo; 04209 *cause = AST_CAUSE_NOTDEFINED; 04210 04211 if (AST_RWLIST_RDLOCK(&channels)) { 04212 ast_log(LOG_WARNING, "Unable to lock channel list\n"); 04213 return NULL; 04214 } 04215 04216 AST_LIST_TRAVERSE(&backends, chan, list) { 04217 if (strcasecmp(type, chan->tech->type)) 04218 continue; 04219 04220 capabilities = chan->tech->capabilities; 04221 fmt = format & AST_FORMAT_AUDIO_MASK; 04222 if (fmt) { 04223 /* We have audio - is it possible to connect the various calls to each other? 04224 (Avoid this check for calls without audio, like text+video calls) 04225 */ 04226 res = ast_translator_best_choice(&fmt, &capabilities); 04227 if (res < 0) { 04228 ast_log(LOG_WARNING, "No translator path exists for channel type %s (native 0x%x) to 0x%x\n", type, chan->tech->capabilities, format); 04229 *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; 04230 AST_RWLIST_UNLOCK(&channels); 04231 return NULL; 04232 } 04233 } 04234 AST_RWLIST_UNLOCK(&channels); 04235 if (!chan->tech->requester) 04236 return NULL; 04237 04238 if (!(c = chan->tech->requester(type, capabilities | videoformat | textformat, data, cause))) 04239 return NULL; 04240 04241 /* no need to generate a Newchannel event here; it is done in the channel_alloc call */ 04242 return c; 04243 } 04244 04245 ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type); 04246 *cause = AST_CAUSE_NOSUCHDRIVER; 04247 AST_RWLIST_UNLOCK(&channels); 04248 04249 return NULL; 04250 }
| 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 | |||
| ) | [read] |
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 4191 of file channel.c.
References __ast_request_and_dial().
Referenced by ast_pbx_outgoing_exten().
04192 { 04193 return __ast_request_and_dial(type, format, data, timeout, outstate, cidnum, cidname, NULL); 04194 }
| int ast_safe_sleep | ( | struct ast_channel * | chan, | |
| int | ms | |||
| ) |
Wait, look for hangups.
Wait for a specified amount of time, looking for hangups.
Definition at line 1427 of file channel.c.
References ast_safe_sleep_conditional().
Referenced by _ast_adsi_transmit_message_full(), alarmreceiver_exec(), ast_dtmf_stream(), ast_senddigit(), builtin_atxfer(), builtin_parkcall(), conf_run(), dictate_exec(), disa_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(), try_calling(), wait_for_hangup(), wait_interval(), wait_moh_exec(), waituntil_exec(), and zapateller_exec().
01428 { 01429 return ast_safe_sleep_conditional(chan, ms, NULL, NULL); 01430 }
| int ast_safe_sleep_conditional | ( | struct ast_channel * | chan, | |
| int | ms, | |||
| int(*)(void *) | cond, | |||
| void * | data | |||
| ) |
Wait, look for hangups and condition arg.
Wait for a specified amount of time, looking for hangups and a condition argument.
Definition at line 1360 of file channel.c.
References ast_channel_lock, ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_channel_unlock, ast_frfree, ast_frisolate(), ast_is_deferrable_frame(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_NOLOCK, AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_HEAD, ast_opt_transmit_silence, ast_queue_frame_head(), ast_read(), ast_waitfor(), cond, f, and ast_channel::generatordata.
Referenced by ast_safe_sleep(), and login_exec().
01361 { 01362 struct ast_frame *f; 01363 struct ast_silence_generator *silgen = NULL; 01364 int res = 0; 01365 AST_LIST_HEAD_NOLOCK(, ast_frame) deferred_frames; 01366 01367 AST_LIST_HEAD_INIT_NOLOCK(&deferred_frames); 01368 01369 /* If no other generator is present, start silencegen while waiting */ 01370 if (ast_opt_transmit_silence && !chan->generatordata) { 01371 silgen = ast_channel_start_silence_generator(chan); 01372 } 01373 01374 while (ms > 0) { 01375 struct ast_frame *dup_f = NULL; 01376 if (cond && ((*cond)(data) == 0)) { 01377 break; 01378 } 01379 ms = ast_waitfor(chan, ms); 01380 if (ms < 0) { 01381 res = -1; 01382 break; 01383 } 01384 if (ms > 0) { 01385 f = ast_read(chan); 01386 if (!f) { 01387 res = -1; 01388 break; 01389 } 01390 01391 if (!ast_is_deferrable_frame(f)) { 01392 ast_frfree(f); 01393 continue; 01394 } 01395 01396 if ((dup_f = ast_frisolate(f))) { 01397 if (dup_f != f) { 01398 ast_frfree(f); 01399 } 01400 AST_LIST_INSERT_HEAD(&deferred_frames, dup_f, frame_list); 01401 } 01402 } 01403 } 01404 01405 /* stop silgen if present */ 01406 if (silgen) { 01407 ast_channel_stop_silence_generator(chan, silgen); 01408 } 01409 01410 /* We need to free all the deferred frames, but we only need to 01411 * queue the deferred frames if there was no error and no 01412 * hangup was received 01413 */ 01414 ast_channel_lock(chan); 01415 while ((f = AST_LIST_REMOVE_HEAD(&deferred_frames, frame_list))) { 01416 if (!res) { 01417 ast_queue_frame_head(chan, f); 01418 } 01419 ast_frfree(f); 01420 } 01421 ast_channel_unlock(chan); 01422 01423 return res; 01424 }
| int ast_say_character_str | ( | struct ast_channel * | chan, | |
| const char * | str, | |||
| const char * | ints, | |||
| const char * | lang | |||
| ) |
Definition at line 6084 of file channel.c.
References ast_say_character_str_full.
Referenced by common_exec(), pbx_builtin_saycharacters(), play_mailbox_owner(), rpt_tele_thread(), saycharstr(), and saynode().
06086 { 06087 return ast_say_character_str_full(chan, str, ints, lang, -1, -1); 06088 }
| int ast_say_digit_str | ( | struct ast_channel * | chan, | |
| const char * | num, | |||
| const char * | ints, | |||
| const char * | lang | |||
| ) |
says digits of a string
| chan | channel to act upon | |
| num | string to speak | |
| ints | which dtmf to interrupt on | |
| lang | language to speak in |
Vocally says the digits of a given string
| 0 | on succes | |
| DTMF | if interrupted | |
| -1 | on failure |
Definition at line 6078 of file channel.c.
References ast_say_digit_str_full.
Referenced by forward_message(), invent_message(), mgcp_ss(), pbx_builtin_saydigits(), play_message_callerid(), and ss_thread().
06080 { 06081 return ast_say_digit_str_full(chan, str, ints, lang, -1, -1); 06082 }
| int ast_say_digits | ( | struct ast_channel * | chan, | |
| int | num, | |||
| const char * | ints, | |||
| const char * | lang | |||
| ) |
says digits
| chan | channel to act upon | |
| num | number to speak | |
| ints | which dtmf to interrupt on | |
| lang | language to speak |
Vocally says digits of a given number
| 0 | on success | |
| DTMF | if interrupted | |
| -1 | on failure |
Definition at line 6072 of file channel.c.
References ast_say_digits_full().
Referenced by common_exec(), conf_exec(), conf_run(), park_call_full(), parkandannounce_exec(), and rpt_tele_thread().
06074 { 06075 return ast_say_digits_full(chan, num, ints, lang, -1, -1); 06076 }
| int ast_say_digits_full | ( | struct ast_channel * | chan, | |
| int | num, | |||
| const char * | ints, | |||
| const char * | lang, | |||
| int | audiofd, | |||
| int | ctrlfd | |||
| ) |
Definition at line 6096 of file channel.c.
References ast_say_digit_str_full.
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().
06098 { 06099 char buf[256]; 06100 06101 snprintf(buf, sizeof(buf), "%d", num); 06102 06103 return ast_say_digit_str_full(chan, buf, ints, lang, audiofd, ctrlfd); 06104 }
| int ast_say_enumeration | ( | struct ast_channel * | chan, | |
| int | num, | |||
| const char * | ints, | |||
| const char * | lang, | |||
| const char * | options | |||
| ) |
says an enumeration
| chan | channel to say them enumeration on | |
| num | number to say on the channel | |
| ints | which dtmf to interrupt on | |
| lang | language to speak the enumeration | |
| options | set to 'f' for female, 'm' for male, 'c' for commune, 'n' for neuter, 'p' for plural |
Vocally says an enumeration on a given channel (first, sencond, third, forth, thirtyfirst, hundredth, ....) Especially useful for dates and messages. Says 'last' if num equals to INT_MAX
| 0 | on success | |
| DTMF | digit on interrupt | |
| -1 | on failure |
Definition at line 6066 of file channel.c.
References ast_say_enumeration_full.
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().
06068 { 06069 return ast_say_enumeration_full(chan, num, ints, language, options, -1, -1); 06070 }
| int ast_say_number | ( | struct ast_channel * | chan, | |
| int | num, | |||
| const char * | ints, | |||
| const char * | lang, | |||
| const char * | options | |||
| ) |
says a number
| chan | channel to say them number on | |
| num | number to say on the channel | |
| ints | which dtmf to interrupt on | |
| lang | language to speak the number | |
| options | set to 'f' for female, 'm' for male, 'c' for commune, 'n' for neuter, 'p' for plural |
Vocally says a number on a given channel
| 0 | on success | |
| DTMF | digit on interrupt | |
| -1 | on failure |
Definition at line 6060 of file channel.c.
References ast_say_number_full.
Referenced by announce_user_count(), 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(), try_calling(), vm_intro_gr(), vm_intro_he(), vm_intro_multilang(), vm_intro_pt(), and vm_intro_pt_BR().
06062 { 06063 return ast_say_number_full(chan, num, ints, language, options, -1, -1); 06064 }
| int ast_say_phonetic_str | ( | struct ast_channel * | chan, | |
| const char * | str, | |||
| const char * | ints, | |||
| const char * | lang | |||
| ) |
Definition at line 6090 of file channel.c.
References ast_say_phonetic_str_full.
Referenced by pbx_builtin_sayphonetic().
06092 { 06093 return ast_say_phonetic_str_full(chan, str, ints, lang, -1, -1); 06094 }
| 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 3455 of file channel.c.
References AST_DEFAULT_EMULATE_DTMF_DURATION, ast_safe_sleep(), ast_senddigit_begin(), ast_senddigit_end(), 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().
03456 { 03457 if (chan->tech->send_digit_begin) { 03458 ast_senddigit_begin(chan, digit); 03459 ast_safe_sleep(chan, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION)); 03460 } 03461 03462 return ast_senddigit_end(chan, digit, (duration >= AST_DEFAULT_EMULATE_DTMF_DURATION ? duration : AST_DEFAULT_EMULATE_DTMF_DURATION)); 03463 }
| 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 3397 of file channel.c.
References ast_debug, ast_playtones_start(), ast_channel_tech::send_digit_begin, and ast_channel::tech.
Referenced by agent_digit_begin(), ast_senddigit(), and ast_write().
03398 { 03399 /* Device does not support DTMF tones, lets fake 03400 * it by doing our own generation. */ 03401 static const char* dtmf_tones[] = { 03402 "941+1336", /* 0 */ 03403 "697+1209", /* 1 */ 03404 "697+1336", /* 2 */ 03405 "697+1477", /* 3 */ 03406 "770+1209", /* 4 */ 03407 "770+1336", /* 5 */ 03408 "770+1477", /* 6 */ 03409 "852+1209", /* 7 */ 03410 "852+1336", /* 8 */ 03411 "852+1477", /* 9 */ 03412 "697+1633", /* A */ 03413 "770+1633", /* B */ 03414 "852+1633", /* C */ 03415 "941+1633", /* D */ 03416 "941+1209", /* * */ 03417 "941+1477" /* # */ 03418 }; 03419 03420 if (!chan->tech->send_digit_begin) 03421 return 0; 03422 03423 if (!chan->tech->send_digit_begin(chan, digit)) 03424 return 0; 03425 03426 if (digit >= '0' && digit <='9') 03427 ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0); 03428 else if (digit >= 'A' && digit <= 'D') 03429 ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0); 03430 else if (digit == '*') 03431 ast_playtones_start(chan, 0, dtmf_tones[14], 0); 03432 else if (digit == '#') 03433 ast_playtones_start(chan, 0, dtmf_tones[15], 0); 03434 else { 03435 /* not handled */ 03436 ast_debug(1, "Unable to generate DTMF tone '%c' for '%s'\n", digit, chan->name); 03437 } 03438 03439 return 0; 03440 }
| 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 3442 of file channel.c.
References ast_playtones_stop(), ast_channel::generator, ast_channel_tech::send_digit_end, and ast_channel::tech.
Referenced by agent_digit_end(), ast_senddigit(), and ast_write().
03443 { 03444 int res = -1; 03445 03446 if (chan->tech->send_digit_end) 03447 res = chan->tech->send_digit_end(chan, digit, duration); 03448 03449 if (res && chan->generator) 03450 ast_playtones_stop(chan); 03451 03452 return 0; 03453 }
| 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 |
Write text to a display on a channel
| 0 | on success | |
| -1 | on failure |
Definition at line 3384 of file channel.c.
References ast_check_hangup(), ast_clear_flag, AST_FLAG_BLOCKING, AST_FLAG_ZOMBIE, ast_test_flag, CHECK_BLOCKING, ast_channel_tech::send_text, and ast_channel::tech.
Referenced by action_sendtext(), agent_sendtext(), handle_sendtext(), send_newkey(), and sendtext_exec().
03385 { 03386 int res = 0; 03387 /* Stop if we're a zombie or need a soft hangup */ 03388 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) 03389 return -1; 03390 CHECK_BLOCKING(chan); 03391 if (chan->tech->send_text) 03392 res = chan->tech->send_text(chan, text); 03393 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03394 return res; 03395 }
| 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 4893 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_free, ast_strdup, 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(), callerid_write(), dahdi_read(), dial_exec_full(), disa_exec(), do_forward(), feature_request_and_dial(), findmeexec(), handle_setcallerid(), mgcp_ss(), privacy_exec(), read_config(), rpt_exec(), skinny_newcall(), and ss_thread().
04894 { 04895 ast_channel_lock(chan); 04896 04897 if (cid_num) { 04898 if (chan->cid.cid_num) 04899 ast_free(chan->cid.cid_num); 04900 chan->cid.cid_num = ast_strdup(cid_num); 04901 } 04902 if (cid_name) { 04903 if (chan->cid.cid_name) 04904 ast_free(chan->cid.cid_name); 04905 chan->cid.cid_name = ast_strdup(cid_name); 04906 } 04907 if (cid_ani) { 04908 if (chan->cid.cid_ani) 04909 ast_free(chan->cid.cid_ani); 04910 chan->cid.cid_ani = ast_strdup(cid_ani); 04911 } 04912 04913 report_new_callerid(chan); 04914 04915 ast_channel_unlock(chan); 04916 }
| 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 3929 of file channel.c.
References 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(), bridge_channel_join(), bridge_make_compatible(), build_conf(), conf_run(), connect_link(), dictate_exec(), do_waiting(), eagi_exec(), echo_exec(), gtalk_rtp_read(), handle_recordfile(), handle_speechrecognize(), ices_exec(), isAnsweringMachine(), jack_exec(), jingle_rtp_read(), login_exec(), measurenoise(), mgcp_rtp_read(), oh323_rtp_read(), old_milliwatt_exec(), process_sdp(), record_exec(), rpt(), rpt_exec(), setup_rtp_connection(), sip_rtp_read(), skinny_rtp_read(), socket_process(), speech_background(), transmit_audio(), and unistim_rtp_read().
03930 { 03931 return set_format(chan, fmt, &chan->rawreadformat, &chan->readformat, 03932 &chan->readtrans, 0); 03933 }
| 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 |
Variable names can be for a regular channel variable or a dialplan function that has the ability to be written to.
Definition at line 5837 of file channel.c.
References 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().
05838 { 05839 struct ast_variable *cur; 05840 05841 for (cur = vars; cur; cur = cur->next) 05842 pbx_builtin_setvar_helper(chan, cur->name, cur->value); 05843 }
| 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 3935 of file channel.c.
References 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(), bridge_channel_join(), bridge_make_compatible(), build_conf(), chanspy_exec(), conf_run(), connect_link(), echo_exec(), extenspy_exec(), gtalk_rtp_read(), jack_exec(), 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().
03936 { 03937 return set_format(chan, fmt, &chan->rawwriteformat, &chan->writeformat, 03938 &chan->writetrans, 1); 03939 }
| int ast_setstate | ( | struct ast_channel * | chan, | |
| enum ast_channel_state | state | |||
| ) |
Change the state of a channel.
Definition at line 4918 of file channel.c.
References ast_channel::_state, AST_CHANNEL_NAME, ast_copy_string(), AST_DEVICE_UNKNOWN, ast_devstate_changed_literal(), ast_state2str(), ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, EVENT_FLAG_CALL, manager_event, name, and S_OR.
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().
04919 { 04920 int oldstate = chan->_state; 04921 char name[AST_CHANNEL_NAME], *dashptr; 04922 04923 if (oldstate == state) 04924 return 0; 04925 04926 ast_copy_string(name, chan->name, sizeof(name)); 04927 if ((dashptr = strrchr(name, '-'))) { 04928 *dashptr = '\0'; 04929 } 04930 04931 chan->_state = state; 04932 04933 /* We have to pass AST_DEVICE_UNKNOWN here because it is entirely possible that the channel driver 04934 * for this channel is using the callback method for device state. If we pass in an actual state here 04935 * we override what they are saying the state is and things go amuck. */ 04936 ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, name); 04937 04938 /* setstate used to conditionally report Newchannel; this is no more */ 04939 manager_event(EVENT_FLAG_CALL, 04940 "Newstate", 04941 "Channel: %s\r\n" 04942 "ChannelState: %d\r\n" 04943 "ChannelStateDesc: %s\r\n" 04944 "CallerIDNum: %s\r\n" 04945 "CallerIDName: %s\r\n" 04946 "Uniqueid: %s\r\n", 04947 chan->name, chan->_state, ast_state2str(chan->_state), 04948 S_OR(chan->cid.cid_num, ""), 04949 S_OR(chan->cid.cid_name, ""), 04950 chan->uniqueid); 04951 04952 return 0; 04953 }
| 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 |
If timers are supported, force a scheduled expiration on the timer fd, at which point we call the callback function / data
Call this function with a rate of 0 to turn off the timer ticks
Definition at line 2467 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().
02468 { 02469 int res; 02470 unsigned int real_rate = rate, max_rate; 02471 02472 ast_channel_lock(c); 02473 02474 if (c->timingfd == -1) { 02475 ast_channel_unlock(c); 02476 return -1; 02477 } 02478 02479 if (!func) { 02480 rate = 0; 02481 data = NULL; 02482 } 02483 02484 if (rate && rate > (max_rate = ast_timer_get_max_rate(c->timer))) { 02485 real_rate = max_rate; 02486 } 02487 02488 ast_debug(1, "Scheduling timer at (%u requested / %u actual) timer ticks per second\n", rate, real_rate); 02489 02490 res = ast_timer_set_rate(c->timer, real_rate); 02491 02492 c->timingfunc = func; 02493 c->timingdata = data; 02494 02495 ast_channel_unlock(c); 02496 02497 return res; 02498 }
| 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 515 of file channel.c.
Referenced by handle_request_options().
00516 { 00517 return shutting_down; 00518 }
| int ast_softhangup | ( | struct ast_channel * | chan, | |
| int | cause | |||
| ) |
Softly hangup a channel, lock.
Softly hangup up a channel.
Definition at line 1726 of file channel.c.
References ast_channel_lock, ast_channel_unlock, and ast_softhangup_nolock().
Referenced by __ast_module_user_hangup_all(), __ast_pbx_run(), __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().
01727 { 01728 int res; 01729 01730 ast_channel_lock(chan); 01731 res = ast_softhangup_nolock(chan, cause); 01732 ast_channel_unlock(chan); 01733 01734 return res; 01735 }
| int ast_softhangup_nolock | ( | struct ast_channel * | chan, | |
| int | cause | |||
| ) |
Softly hangup a channel, don't lock.
Softly hangup up a channel (no channel lock).
Definition at line 1713 of file channel.c.
References ast_channel::_softhangup, ast_debug, AST_FLAG_BLOCKING, ast_null_frame, ast_queue_frame(), ast_test_flag, and ast_channel::blocker.
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().
01714 { 01715 ast_debug(1, "Soft-Hanging up channel '%s'\n", chan->name); 01716 /* Inform channel driver that we need to be hung up, if it cares */ 01717 chan->_softhangup |= cause; 01718 ast_queue_frame(chan, &ast_null_frame); 01719 /* Interrupt any poll call or such */ 01720 if (ast_test_flag(chan, AST_FLAG_BLOCKING)) 01721 pthread_kill(chan->blocker, SIGURG); 01722 return 0; 01723 }
| const char* ast_state2str | ( | enum ast_channel_state | state | ) |
Gives the string form of a given channel state.
Definition at line 656 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(), STATE2STR_BUFSIZE, and state2str_threadbuf.
Referenced by __ast_channel_alloc_ap(), action_coreshowchannels(), action_status(), 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().
00657 { 00658 char *buf; 00659 00660 switch (state) { 00661 case AST_STATE_DOWN: 00662 return "Down"; 00663 case AST_STATE_RESERVED: 00664 return "Rsrvd"; 00665 case AST_STATE_OFFHOOK: 00666 return "OffHook"; 00667 case AST_STATE_DIALING: 00668 return "Dialing"; 00669 case AST_STATE_RING: 00670 return "Ring"; 00671 case AST_STATE_RINGING: 00672 return "Ringing"; 00673 case AST_STATE_UP: 00674 return "Up"; 00675 case AST_STATE_BUSY: 00676 return "Busy"; 00677 case AST_STATE_DIALING_OFFHOOK: 00678 return "Dialing Offhook"; 00679 case AST_STATE_PRERING: 00680 return "Pre-ring"; 00681 default: 00682 if (!(buf = ast_threadstorage_get(&state2str_threadbuf, STATE2STR_BUFSIZE))) 00683 return "Unknown"; 00684 snprintf(buf, STATE2STR_BUFSIZE, "Unknown (%d)", state); 00685 return buf; 00686 } 00687 }
| int ast_str2cause | ( | const char * | name | ) |
| 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 5694 of file channel.c.
References ast_frfree, ast_read(), ast_tonepair_start(), ast_waitfor(), f, and ast_channel::generatordata.
Referenced by zapateller_exec().
05695 { 05696 int res; 05697 05698 if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol))) 05699 return res; 05700 05701 /* Give us some wiggle room */ 05702 while (chan->generatordata && ast_waitfor(chan, 100) >= 0) { 05703 struct ast_frame *f = ast_read(chan); 05704 if (f) 05705 ast_frfree(f); 05706 else 05707 return -1; 05708 } 05709 return 0; 05710 }
| int ast_tonepair_start | ( | struct ast_channel * | chan, | |
| int | freq1, | |||
| int | freq2, | |||
| int | duration, | |||
| int | vol | |||
| ) |
Start a tone going
Definition at line 5676 of file channel.c.
References ast_activate_generator(), 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().
| void ast_tonepair_stop | ( | struct ast_channel * | chan | ) |
Stop a tone from playing
Definition at line 5689 of file channel.c.
References ast_deactivate_generator().
Referenced by sendnoise().
05690 { 05691 ast_deactivate_generator(chan); 05692 }
| int ast_transfer | ( | struct ast_channel * | chan, | |
| char * | dest | |||
| ) |
Transfer a call to dest, if the channel supports transfer.
Transfer a channel (if supported). Returns -1 on error, 0 if not supported and 1 if supported and requested.
Called by:
Definition at line 4279 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_FLAG_ZOMBIE, ast_test_flag, ast_channel::tech, and ast_channel_tech::transfer.
Referenced by transfer_exec().
04280 { 04281 int res = -1; 04282 04283 /* Stop if we're a zombie or need a soft hangup */ 04284 ast_channel_lock(chan); 04285 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) { 04286 if (chan->tech->transfer) { 04287 res = chan->tech->transfer(chan, dest); 04288 if (!res) 04289 res = 1; 04290 } else 04291 res = 0; 04292 } 04293 ast_channel_unlock(chan); 04294 return res; 04295 }
| char* ast_transfercapability2str | ( | int | transfercapability | ) | const |
Gives the string form of a given transfer capability.
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 690 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().
00691 { 00692 switch (transfercapability) { 00693 case AST_TRANS_CAP_SPEECH: 00694 return "SPEECH"; 00695 case AST_TRANS_CAP_DIGITAL: 00696 return "DIGITAL"; 00697 case AST_TRANS_CAP_RESTRICTED_DIGITAL: 00698 return "RESTRICTED_DIGITAL"; 00699 case AST_TRANS_CAP_3_1K_AUDIO: 00700 return "3K1AUDIO"; 00701 case AST_TRANS_CAP_DIGITAL_W_TONES: 00702 return "DIGITAL_W_TONES"; 00703 case AST_TRANS_CAP_VIDEO: 00704 return "VIDEO"; 00705 default: 00706 return "UNKNOWN"; 00707 } 00708 }
| void ast_uninstall_music_functions | ( | void | ) |
Definition at line 5757 of file channel.c.
References ast_moh_cleanup_ptr, ast_moh_start_ptr, and ast_moh_stop_ptr.
Referenced by unload_module().
05758 { 05759 ast_moh_start_ptr = NULL; 05760 ast_moh_stop_ptr = NULL; 05761 ast_moh_cleanup_ptr = NULL; 05762 }
| 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 2451 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_waiting(), echo_exec(), handle_recordfile(), handle_speechrecognize(), ices_exec(), isAnsweringMachine(), jack_exec(), launch_asyncagi(), measurenoise(), mp3_exec(), NBScat_exec(), receive_dtmf_digits(), record_exec(), 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().
02452 { 02453 int oldms = ms; /* -1 if no timeout */ 02454 02455 ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms); 02456 if ((ms < 0) && (oldms < 0)) 02457 ms = 0; 02458 return ms; 02459 }
| struct ast_channel* ast_waitfor_n | ( | struct ast_channel ** | chan, | |
| int | n, | |||
| int * | ms | |||
| ) | [read] |
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 2446 of file channel.c.
References ast_waitfor_nandfds().
Referenced by ast_generic_bridge(), ast_udptl_bridge(), autoservice_run(), bridge_native_loop(), bridge_p2p_loop(), dahdi_bridge(), dial_exec_full(), feature_request_and_dial(), generic_thread_loop(), iax2_bridge(), misdn_bridge(), monitor_dial(), rpt(), rpt_exec(), wait_for_answer(), and wait_for_winner().
02447 { 02448 return ast_waitfor_nandfds(c, n, NULL, 0, NULL, NULL, ms); 02449 }
| int ast_waitfor_n_fd | ( | int * | fds, | |
| int | n, | |||
| int * | ms, | |||
| int * | exception | |||
| ) |
Wait for x amount of time on a file descriptor to have input.
Waits for input on an fd This version works on fd's only. Be careful with it.
Definition at line 2086 of file channel.c.
References ast_waitfor_nandfds().
Referenced by dundi_lookup_internal(), dundi_precache_internal(), and softmix_bridge_thread().
02087 { 02088 int winner = -1; 02089 ast_waitfor_nandfds(NULL, 0, fds, n, exception, &winner, ms); 02090 return winner; 02091 }
| struct ast_channel* ast_waitfor_nandfds | ( | struct ast_channel ** | c, | |
| int | n, | |||
| int * | fds, | |||
| int | nfds, | |||
| int * | exception, | |||
| int * | outfd, | |||
| int * | ms | |||
| ) | [read] |
Wait for x amount of time on a file descriptor to have input.
Waits for activity on a group of channels.
Definition at line 2098 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(), CHECK_BLOCKING, errno, ast_channel::fdno, and LOG_WARNING.
Referenced by ast_waitfor(), ast_waitfor_n(), ast_waitfor_n_fd(), ast_waitfordigit_full(), bridge_channel_join_multithreaded(), conf_run(), eivr_comm(), find_cache(), multiplexed_thread_function(), run_agi(), and waitstream_core().
02101 { 02102 struct timeval start = { 0 , 0 }; 02103 struct pollfd *pfds = NULL; 02104 int res; 02105 long rms; 02106 int x, y, max; 02107 int sz; 02108 struct timeval now = { 0, 0 }; 02109 struct timeval whentohangup = { 0, 0 }, diff; 02110 struct ast_channel *winner = NULL; 02111 struct fdmap { 02112 int chan; 02113 int fdno; 02114 } *fdmap = NULL; 02115 02116 if ((sz = n * AST_MAX_FDS + nfds)) { 02117 pfds = alloca(sizeof(*pfds) * sz); 02118 fdmap = alloca(sizeof(*fdmap) * sz); 02119 } 02120 02121 if (outfd) 02122 *outfd = -99999; 02123 if (exception) 02124 *exception = 0; 02125 02126 /* Perform any pending masquerades */ 02127 for (x = 0; x < n; x++) { 02128 ast_channel_lock(c[x]); 02129 if (c[x]->masq && ast_do_masquerade(c[x])) { 02130 ast_log(LOG_WARNING, "Masquerade failed\n"); 02131 *ms = -1; 02132 ast_channel_unlock(c[x]); 02133 return NULL; 02134 } 02135 if (!ast_tvzero(c[x]->whentohangup)) { 02136 if (ast_tvzero(whentohangup)) 02137 now = ast_tvnow(); 02138 diff = ast_tvsub(c[x]->whentohangup, now); 02139 if (diff.tv_sec < 0 || ast_tvzero(diff)) { 02140 /* Should already be hungup */ 02141 c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT; 02142 ast_channel_unlock(c[x]); 02143 return c[x]; 02144 } 02145 if (ast_tvzero(whentohangup) || ast_tvcmp(diff, whentohangup) < 0) 02146 whentohangup = diff; 02147 } 02148 ast_channel_unlock(c[x]); 02149 } 02150 /* Wait full interval */ 02151 rms = *ms; 02152 /* INT_MAX, not LONG_MAX, because it matters on 64-bit */ 02153 if (!ast_tvzero(whentohangup) && whentohangup.tv_sec < INT_MAX / 1000) { 02154 rms = whentohangup.tv_sec * 1000 + whentohangup.tv_usec / 1000; /* timeout in milliseconds */ 02155 if (*ms >= 0 && *ms < rms) { /* original *ms still smaller */ 02156 rms = *ms; 02157 } 02158 } else if (!ast_tvzero(whentohangup) && rms < 0) { 02159 /* Tiny corner case... call would need to last >24 days */ 02160 rms = INT_MAX; 02161 } 02162 /* 02163 * Build the pollfd array, putting the channels' fds first, 02164 * followed by individual fds. Order is important because 02165 * individual fd's must have priority over channel fds. 02166 */ 02167 max = 0; 02168 for (x = 0; x < n; x++) { 02169 for (y = 0; y < AST_MAX_FDS; y++) { 02170 fdmap[max].fdno = y; /* fd y is linked to this pfds */ 02171 fdmap[max].chan = x; /* channel x is linked to this pfds */ 02172 max += ast_add_fd(&pfds[max], c[x]->fds[y]); 02173 } 02174 CHECK_BLOCKING(c[x]); 02175 } 02176 /* Add the individual fds */ 02177 for (x = 0; x < nfds; x++) { 02178 fdmap[max].chan = -1; 02179 max += ast_add_fd(&pfds[max], fds[x]); 02180 } 02181 02182 if (*ms > 0) 02183 start = ast_tvnow(); 02184 02185 if (sizeof(int) == 4) { /* XXX fix timeout > 600000 on linux x86-32 */ 02186 do { 02187 int kbrms = rms; 02188 if (kbrms > 600000) 02189 kbrms = 600000; 02190 res = ast_poll(pfds, max, kbrms); 02191 if (!res) 02192 rms -= kbrms; 02193 } while (!res && (rms > 0)); 02194 } else { 02195 res = ast_poll(pfds, max, rms); 02196 } 02197 for (x = 0; x < n; x++) 02198 ast_clear_flag(c[x], AST_FLAG_BLOCKING); 02199 if (res < 0) { /* Simulate a timeout if we were interrupted */ 02200 if (errno != EINTR) 02201 *ms = -1; 02202 return NULL; 02203 } 02204 if (!ast_tvzero(whentohangup)) { /* if we have a timeout, check who expired */ 02205 now = ast_tvnow(); 02206 for (x = 0; x < n; x++) { 02207 if (!ast_tvzero(c[x]->whentohangup) && ast_tvcmp(c[x]->whentohangup, now) <= 0) { 02208 c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT; 02209 if (winner == NULL) 02210 winner = c[x]; 02211 } 02212 } 02213 } 02214 if (res == 0) { /* no fd ready, reset timeout and done */ 02215 *ms = 0; /* XXX use 0 since we may not have an exact timeout. */ 02216 return winner; 02217 } 02218 /* 02219 * Then check if any channel or fd has a pending event. 02220 * Remember to check channels first and fds last, as they 02221 * must have priority on setting 'winner' 02222 */ 02223 for (x = 0; x < max; x++) { 02224 res = pfds[x].revents; 02225 if (res == 0) 02226 continue; 02227 if (fdmap[x].chan >= 0) { /* this is a channel */ 02228 winner = c[fdmap[x].chan]; /* override previous winners */ 02229 if (res & POLLPRI) 02230 ast_set_flag(winner, AST_FLAG_EXCEPTION); 02231 else 02232 ast_clear_flag(winner, AST_FLAG_EXCEPTION); 02233 winner->fdno = fdmap[x].fdno; 02234 } else { /* this is an fd */ 02235 if (outfd) 02236 *outfd = pfds[x].fd; 02237 if (exception) 02238 *exception = (res & POLLPRI) ? -1 : 0; 02239 winner = NULL; 02240 } 02241 } 02242 if (*ms > 0) { 02243 *ms -= ast_tvdiff_ms(ast_tvnow(), start); 02244 if (*ms < 0) 02245 *ms = 0; 02246 } 02247 return winner; 02248 }
| 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 2462 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(), bridge_channel_feature(), 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().
02463 { 02464 return ast_waitfordigit_full(c, ms, -1, -1); 02465 }
| 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 2500 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(), ast_frame::data, ast_frame::datalen, errno, f, ast_frame::frametype, LOG_WARNING, ast_frame::ptr, and ast_frame::subclass.
Referenced by ast_readstring_full(), ast_waitfordigit(), handle_getoption(), and handle_waitfordigit().
02501 { 02502 /* Stop if we're a zombie or need a soft hangup */ 02503 if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c)) 02504 return -1; 02505 02506 /* Only look for the end of DTMF, don't bother with the beginning and don't emulate things */ 02507 ast_set_flag(c, AST_FLAG_END_DTMF_ONLY); 02508 02509 /* Wait for a digit, no more than ms milliseconds total. */ 02510 02511 while (ms) { 02512 struct ast_channel *rchan; 02513 int outfd=-1; 02514 02515 errno = 0; 02516 rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms); 02517 02518 if (!rchan && outfd < 0 && ms) { 02519 if (errno == 0 || errno == EINTR) 02520 continue; 02521 ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno)); 02522 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 02523 return -1; 02524 } else if (outfd > -1) { 02525 /* The FD we were watching has something waiting */ 02526 ast_log(LOG_WARNING, "The FD we were waiting for has something waiting. Waitfordigit returning numeric 1\n"); 02527 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 02528 return 1; 02529 } else if (rchan) { 02530 int res; 02531 struct ast_frame *f = ast_read(c); 02532 if (!f) 02533 return -1; 02534 02535 switch (f->frametype) { 02536 case AST_FRAME_DTMF_BEGIN: 02537 break; 02538 case AST_FRAME_DTMF_END: 02539 res = f->subclass; 02540 ast_frfree(f); 02541 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 02542 return res; 02543 case AST_FRAME_CONTROL: 02544 switch (f->subclass) { 02545 case AST_CONTROL_HANGUP: 02546 ast_frfree(f); 02547 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 02548 return -1; 02549 case AST_CONTROL_RINGING: 02550 case AST_CONTROL_ANSWER: 02551 case AST_CONTROL_SRCUPDATE: 02552 case AST_CONTROL_SRCCHANGE: 02553 /* Unimportant */ 02554 break; 02555 default: 02556 ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass); 02557 break; 02558 } 02559 break; 02560 case AST_FRAME_VOICE: 02561 /* Write audio if appropriate */ 02562 if (audiofd > -1) { 02563 if (write(audiofd, f->data.ptr, f->datalen) < 0) { 02564 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); 02565 } 02566 } 02567 default: 02568 /* Ignore */ 02569 break; 02570 } 02571 ast_frfree(f); 02572 } 02573 } 02574 02575 ast_clear_flag(c, AST_FLAG_END_DTMF_ONLY); 02576 02577 return 0; /* Time is up */ 02578 }
| struct ast_channel* ast_walk_channel_by_exten_locked | ( | const struct ast_channel * | chan, | |
| const char * | exten, | |||
| const char * | context | |||
| ) | [read] |
Get next channel by exten (and optionally context) and lock it.
Definition at line 1309 of file channel.c.
References channel_find_locked().
Referenced by next_channel().
01311 { 01312 return channel_find_locked(chan, NULL, 0, context, exten); 01313 }
| struct ast_channel* ast_walk_channel_by_name_prefix_locked | ( | const struct ast_channel * | chan, | |
| const char * | name, | |||
| const int | namelen | |||
| ) | [read] |
Get next channel by name prefix and lock it.
Get channel by name or uniqueid prefix (locks channel).
Definition at line 1296 of file channel.c.
References channel_find_locked().
Referenced by my_ast_get_channel_by_name_locked(), next_channel(), and softhangup_exec().
01298 { 01299 return channel_find_locked(chan, name, namelen, NULL, NULL); 01300 }
| 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 3597 of file channel.c.
References ast_channel::_softhangup, apply_plc(), ast_audiohook_detach_list(), AST_AUDIOHOOK_DIRECTION_WRITE, ast_audiohook_write_list(), ast_audiohook_write_list_empty(), 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_SLINEAR, 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_opt_generic_plc, ast_seekstream(), ast_senddigit_begin(), ast_senddigit_end(), AST_SOFTHANGUP_DEV, ast_test_flag, ast_translate(), ast_writestream(), ast_channel::audiohooks, calc_monitor_jump(), 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, 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_frame::src, 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_generic_bridge(), ast_prod(), ast_readaudio_callback(), ast_readvideo_callback(), ast_udptl_bridge(), ast_write_video(), bridge_native_loop(), bridge_p2p_loop(), conf_queue_dtmf(), conf_run(), dahdi_bridge(), dictate_exec(), echo_exec(), fax_generator_generate(), feature_request_and_dial(), function_ilink(), gen_generate(), handle_jack_audio(), handle_link_data(), iax2_bridge(), jb_get_and_deliver(), linear_generator(), milliwatt_generate(), misdn_bridge(), moh_files_generator(), moh_generate(), mp3_exec(), multiplexed_bridge_write(), NBScat_exec(), playtones_generator(), rpt(), rpt_exec(), send_link_dtmf(), send_link_keyquery(), send_tone_burst(), send_usb_txt(), send_waveform_to_channel(), silence_generator_generate(), simple_bridge_write(), sms_generate(), softmix_bridge_poke(), softmix_bridge_write(), spy_generate(), t38_tx_packet_handler(), tonepair_generator(), and wait_for_answer().
03598 { 03599 int res = -1; 03600 struct ast_frame *f = NULL; 03601 int count = 0; 03602 03603 /*Deadlock avoidance*/ 03604 while(ast_channel_trylock(chan)) { 03605 /*cannot goto done since the channel is not locked*/ 03606 if(count++ > 10) { 03607 ast_debug(1, "Deadlock avoided for write to channel '%s'\n", chan->name); 03608 return 0; 03609 } 03610 usleep(1); 03611 } 03612 /* Stop if we're a zombie or need a soft hangup */ 03613 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) 03614 goto done; 03615 03616 /* Handle any pending masquerades */ 03617 if (chan->masq && ast_do_masquerade(chan)) { 03618 ast_log(LOG_WARNING, "Failed to perform masquerade\n"); 03619 goto done; 03620 } 03621 if (chan->masqr) { 03622 res = 0; /* XXX explain, why 0 ? */ 03623 goto done; 03624 } 03625 if (chan->generatordata && (!fr->src || strcasecmp(fr->src, "ast_prod"))) { 03626 if (ast_test_flag(chan, AST_FLAG_WRITE_INT)) { 03627 ast_deactivate_generator(chan); 03628 } else { 03629 if (fr->frametype == AST_FRAME_DTMF_END) { 03630 /* There is a generator running while we're in the middle of a digit. 03631 * It's probably inband DTMF, so go ahead and pass it so it can 03632 * stop the generator */ 03633 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03634 ast_channel_unlock(chan); 03635 res = ast_senddigit_end(chan, fr->subclass, fr->len); 03636 ast_channel_lock(chan); 03637 CHECK_BLOCKING(chan); 03638 } else if (fr->frametype == AST_FRAME_CONTROL && fr->subclass == AST_CONTROL_UNHOLD) { 03639 /* This is a side case where Echo is basically being called and the person put themselves on hold and took themselves off hold */ 03640 res = (chan->tech->indicate == NULL) ? 0 : 03641 chan->tech->indicate(chan, fr->subclass, fr->data.ptr, fr->datalen); 03642 } 03643 res = 0; /* XXX explain, why 0 ? */ 03644 goto done; 03645 } 03646 } 03647 /* High bit prints debugging */ 03648 if (chan->fout & DEBUGCHAN_FLAG) 03649 ast_frame_dump(chan->name, fr, ">>"); 03650 CHECK_BLOCKING(chan); 03651 switch (fr->frametype) { 03652 case AST_FRAME_CONTROL: 03653 res = (chan->tech->indicate == NULL) ? 0 : 03654 chan->tech->indicate(chan, fr->subclass, fr->data.ptr, fr->datalen); 03655 break; 03656 case AST_FRAME_DTMF_BEGIN: 03657 if (chan->audiohooks) { 03658 struct ast_frame *old_frame = fr; 03659 fr = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr); 03660 if (old_frame != fr) 03661 f = fr; 03662 } 03663 send_dtmf_event(chan, "Sent", fr->subclass, "Yes", "No"); 03664 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03665 ast_channel_unlock(chan); 03666 res = ast_senddigit_begin(chan, fr->subclass); 03667 ast_channel_lock(chan); 03668 CHECK_BLOCKING(chan); 03669 break; 03670 case AST_FRAME_DTMF_END: 03671 if (chan->audiohooks) { 03672 struct ast_frame *new_frame = fr; 03673 03674 new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr); 03675 if (new_frame != fr) { 03676 ast_frfree(new_frame); 03677 } 03678 } 03679 send_dtmf_event(chan, "Sent", fr->subclass, "No", "Yes"); 03680 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03681 ast_channel_unlock(chan); 03682 res = ast_senddigit_end(chan, fr->subclass, fr->len); 03683 ast_channel_lock(chan); 03684 CHECK_BLOCKING(chan); 03685 break; 03686 case AST_FRAME_TEXT: 03687 if (fr->subclass == AST_FORMAT_T140) { 03688 res = (chan->tech->write_text == NULL) ? 0 : 03689 chan->tech->write_text(chan, fr); 03690 } else { 03691 res = (chan->tech->send_text == NULL) ? 0 : 03692 chan->tech->send_text(chan, (char *) fr->data.ptr); 03693 } 03694 break; 03695 case AST_FRAME_HTML: 03696 res = (chan->tech->send_html == NULL) ? 0 : 03697 chan->tech->send_html(chan, fr->subclass, (char *) fr->data.ptr, fr->datalen); 03698 break; 03699 case AST_FRAME_VIDEO: 03700 /* XXX Handle translation of video codecs one day XXX */ 03701 res = (chan->tech->write_video == NULL) ? 0 : 03702 chan->tech->write_video(chan, fr); 03703 break; 03704 case AST_FRAME_MODEM: 03705 res = (chan->tech->write == NULL) ? 0 : 03706 chan->tech->write(chan, fr); 03707 break; 03708 case AST_FRAME_VOICE: 03709 if (chan->tech->write == NULL) 03710 break; /*! \todo XXX should return 0 maybe ? */ 03711 03712 if (ast_opt_generic_plc && fr->subclass == AST_FORMAT_SLINEAR) { 03713 apply_plc(chan, fr); 03714 } 03715 03716 /* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */ 03717 if (fr->subclass == chan->rawwriteformat) 03718 f = fr; 03719 else 03720 f = (chan->writetrans) ? ast_translate(chan->writetrans, fr, 0) : fr; 03721 03722 if (!f) { 03723 res = 0; 03724 break; 03725 } 03726 03727 if (chan->audiohooks) { 03728 struct ast_frame *prev = NULL, *new_frame, *cur, *dup; 03729 int freeoldlist = 0; 03730 03731 if (f != fr) { 03732 freeoldlist = 1; 03733 } 03734 03735 /* Since ast_audiohook_write may return a new frame, and the cur frame is 03736 * an item in a list of frames, create a new list adding each cur frame back to it 03737 * regardless if the cur frame changes or not. */ 03738 for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) { 03739 new_frame = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, cur); 03740 03741 /* if this frame is different than cur, preserve the end of the list, 03742 * free the old frames, and set cur to be the new frame */ 03743 if (new_frame != cur) { 03744 03745 /* doing an ast_frisolate here seems silly, but we are not guaranteed the new_frame 03746 * isn't part of local storage, meaning if ast_audiohook_write is called multiple 03747 * times it may override the previous frame we got from it unless we dup it */ 03748 if ((dup = ast_frisolate(new_frame))) { 03749 AST_LIST_NEXT(dup, frame_list) = AST_LIST_NEXT(cur, frame_list); 03750 if (freeoldlist) { 03751 AST_LIST_NEXT(cur, frame_list) = NULL; 03752 ast_frfree(cur); 03753 } 03754 if (new_frame != dup) { 03755 ast_frfree(new_frame); 03756 } 03757 cur = dup; 03758 } 03759 } 03760 03761 /* now, regardless if cur is new or not, add it to the new list, 03762 * if the new list has not started, cur will become the first item. */ 03763 if (prev) { 03764 AST_LIST_NEXT(prev, frame_list) = cur; 03765 } else { 03766 f = cur; /* set f to be the beginning of our new list */ 03767 } 03768 prev = cur; 03769 } 03770 } 03771 03772 /* If Monitor is running on this channel, then we have to write frames out there too */ 03773 /* the translator on chan->writetrans may have returned multiple frames 03774 from the single frame we passed in; if so, feed each one of them to the 03775 monitor */ 03776 if (chan->monitor && chan->monitor->write_stream) { 03777 struct ast_frame *cur; 03778 03779 for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) { 03780 /* XXX must explain this code */ 03781 #ifndef MONITOR_CONSTANT_DELAY 03782 int jump = chan->insmpl - chan->outsmpl - 4 * cur->samples; 03783 if (jump >= 0) { 03784 jump = calc_monitor_jump((chan->insmpl - chan->outsmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format)); 03785 if (ast_seekstream(chan->monitor->write_stream, jump, SEEK_FORCECUR) == -1) 03786 ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n"); 03787 chan->outsmpl += (chan->insmpl - chan->outsmpl) + cur->samples; 03788 } else { 03789 chan->outsmpl += cur->samples; 03790 } 03791 #else 03792 int jump = calc_monitor_jump((chan->insmpl - chan->outsmpl), ast_format_rate(f->subclass), ast_format_rate(chan->monitor->read_stream->fmt->format)); 03793 if (jump - MONITOR_DELAY >= 0) { 03794 if (ast_seekstream(chan->monitor->write_stream, jump - cur->samples, SEEK_FORCECUR) == -1) 03795 ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n"); 03796 chan->outsmpl += chan->insmpl - chan->outsmpl; 03797 } else { 03798 chan->outsmpl += cur->samples; 03799 } 03800 #endif 03801 if (chan->monitor->state == AST_MONITOR_RUNNING) { 03802 if (ast_writestream(chan->monitor->write_stream, cur) < 0) 03803 ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n"); 03804 } 03805 } 03806 } 03807 03808 /* the translator on chan->writetrans may have returned multiple frames 03809 from the single frame we passed in; if so, feed each one of them to the 03810 channel, freeing each one after it has been written */ 03811 if ((f != fr) && AST_LIST_NEXT(f, frame_list)) { 03812 struct ast_frame *cur, *next; 03813 unsigned int skip = 0; 03814 03815 for (cur = f, next = AST_LIST_NEXT(cur, frame_list); 03816 cur; 03817 cur = next, next = cur ? AST_LIST_NEXT(cur, frame_list) : NULL) { 03818 if (!skip) { 03819 if ((res = chan->tech->write(chan, cur)) < 0) { 03820 chan->_softhangup |= AST_SOFTHANGUP_DEV; 03821 skip = 1; 03822 } else if (next) { 03823 /* don't do this for the last frame in the list, 03824 as the code outside the loop will do it once 03825 */ 03826 chan->fout = FRAMECOUNT_INC(chan->fout); 03827 } 03828 } 03829 ast_frfree(cur); 03830 } 03831 03832 /* reset f so the code below doesn't attempt to free it */ 03833 f = NULL; 03834 } else { 03835 res = chan->tech->write(chan, f); 03836 } 03837 break; 03838 case AST_FRAME_NULL: 03839 case AST_FRAME_IAX: 03840 /* Ignore these */ 03841 res = 0; 03842 break; 03843 default: 03844 /* At this point, fr is the incoming frame and f is NULL. Channels do 03845 * not expect to get NULL as a frame pointer and will segfault. Hence, 03846 * we output the original frame passed in. */ 03847 res = chan->tech->write(chan, fr); 03848 break; 03849 } 03850 03851 if (f && f != fr) 03852 ast_frfree(f); 03853 ast_clear_flag(chan, AST_FLAG_BLOCKING); 03854 03855 /* Consider a write failure to force a soft hangup */ 03856 if (res < 0) { 03857 chan->_softhangup |= AST_SOFTHANGUP_DEV; 03858 } else { 03859 chan->fout = FRAMECOUNT_INC(chan->fout); 03860 } 03861 done: 03862 if (chan->audiohooks && ast_audiohook_write_list_empty(chan->audiohooks)) { 03863 /* The list gets recreated if audiohooks are added again later */ 03864 ast_audiohook_detach_list(chan->audiohooks); 03865 chan->audiohooks = NULL; 03866 } 03867 ast_channel_unlock(chan); 03868 return res; 03869 }
| 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 3482 of file channel.c.
References ast_write(), ast_channel::tech, and ast_channel_tech::write_video.
03483 { 03484 int res; 03485 if (!chan->tech->write_video) 03486 return 0; 03487 res = ast_write(chan, fr); 03488 if (!res) 03489 res = 1; 03490 return res; 03491 }
| static void bridge_play_sounds | ( | struct ast_channel * | c0, | |
| struct ast_channel * | c1 | |||
| ) | [static] |
Definition at line 5251 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().
05252 { 05253 const char *s, *sound; 05254 05255 /* See if we need to play an audio file to any side of the bridge */ 05256 05257 ast_channel_lock(c0); 05258 if ((s = pbx_builtin_getvar_helper(c0, "BRIDGE_PLAY_SOUND"))) { 05259 sound = ast_strdupa(s); 05260 ast_channel_unlock(c0); 05261 bridge_playfile(c0, c1, sound, 0); 05262 pbx_builtin_setvar_helper(c0, "BRIDGE_PLAY_SOUND", NULL); 05263 } else { 05264 ast_channel_unlock(c0); 05265 } 05266 05267 ast_channel_lock(c1); 05268 if ((s = pbx_builtin_getvar_helper(c1, "BRIDGE_PLAY_SOUND"))) { 05269 sound = ast_strdupa(s); 05270 ast_channel_unlock(c1); 05271 bridge_playfile(c1, c0, sound, 0); 05272 pbx_builtin_setvar_helper(c1, "BRIDGE_PLAY_SOUND", NULL); 05273 } else { 05274 ast_channel_unlock(c1); 05275 } 05276 }
| static void bridge_playfile | ( | struct ast_channel * | chan, | |
| struct ast_channel * | peer, | |||
| const char * | sound, | |||
| int | remain | |||
| ) | [static] |
Definition at line 4965 of file channel.c.
References ast_autoservice_start(), ast_autoservice_stop(), AST_DIGIT_ANY, ast_say_number(), ast_stream_and_wait(), and sec.
Referenced by ast_channel_bridge(), and bridge_play_sounds().
04966 { 04967 int min = 0, sec = 0, check; 04968 04969 check = ast_autoservice_start(peer); 04970 if (check) 04971 return; 04972 04973 if (remain > 0) { 04974 if (remain / 60 > 1) { 04975 min = remain / 60; 04976 sec = remain % 60; 04977 } else { 04978 sec = remain; 04979 } 04980 } 04981 04982 if (!strcmp(sound,"timeleft")) { /* Queue support */ 04983 ast_stream_and_wait(chan, "vm-youhave", ""); 04984 if (min) { 04985 ast_say_number(chan, min, AST_DIGIT_ANY, chan->language, NULL); 04986 ast_stream_and_wait(chan, "queue-minutes", ""); 04987 } 04988 if (sec) { 04989 ast_say_number(chan, sec, AST_DIGIT_ANY, chan->language, NULL); 04990 ast_stream_and_wait(chan, "queue-seconds", ""); 04991 } 04992 } else { 04993 ast_stream_and_wait(chan, sound, ""); 04994 } 04995 04996 ast_autoservice_stop(peer); 04997 }
| 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 2686 of file channel.c.
Referenced by __ast_read(), and ast_write().
| 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, read] |
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.
Definition at line 1194 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, and msg.
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().
01197 { 01198 const char *msg = prev ? "deadlock" : "initial deadlock"; 01199 int retries; 01200 struct ast_channel *c; 01201 const struct ast_channel *_prev = prev; 01202 01203 for (retries = 0; retries < 200; retries++) { 01204 int done; 01205 /* Reset prev on each retry. See note below for the reason. */ 01206 prev = _prev; 01207 AST_RWLIST_RDLOCK(&channels); 01208 AST_RWLIST_TRAVERSE(&channels, c, chan_list) { 01209 if (prev) { /* look for last item, first, before any evaluation */ 01210 if (c != prev) /* not this one */ 01211 continue; 01212 /* found, prepare to return c->next */ 01213 if ((c = AST_RWLIST_NEXT(c, chan_list)) == NULL) break; 01214 /*!\note 01215 * We're done searching through the list for the previous item. 01216 * Any item after this point, we want to evaluate for a match. 01217 * If we didn't set prev to NULL here, then we would only 01218 * return matches for the first matching item (since the above 01219 * "if (c != prev)" would not permit any other potential 01220 * matches to reach the additional matching logic, below). 01221 * Instead, it would just iterate until it once again found the 01222 * original match, then iterate down to the end of the list and 01223 * quit. 01224 */ 01225 prev = NULL; 01226 } 01227 if (name) { /* want match by name */ 01228 if ((!namelen && strcasecmp(c->name, name) && strcmp(c->uniqueid, name)) || 01229 (namelen && strncasecmp(c->name, name, namelen))) 01230 continue; /* name match failed */ 01231 } else if (exten) { 01232 if (context && strcasecmp(c->context, context) && 01233 strcasecmp(c->macrocontext, context)) 01234 continue; /* context match failed */ 01235 if (strcasecmp(c->exten, exten) && 01236 strcasecmp(c->macroexten, exten)) 01237 continue; /* exten match failed */ 01238 } 01239 /* if we get here, c points to the desired record */ 01240 break; 01241 } 01242 /* exit if chan not found or mutex acquired successfully */ 01243 /* this is slightly unsafe, as we _should_ hold the lock to access c->name */ 01244 done = c == NULL || ast_channel_trylock(c) == 0; 01245 if (!done) { 01246 ast_debug(1, "Avoiding %s for channel '%p'\n", msg, c); 01247 if (retries == 199) { 01248 /* We are about to fail due to a deadlock, so report this 01249 * while we still have the list lock. 01250 */ 01251 ast_debug(1, "Failure, could not lock '%p' after %d retries!\n", c, retries); 01252 /* As we have deadlocked, we will skip this channel and 01253 * see if there is another match. 01254 * NOTE: No point doing this for a full-name match, 01255 * as there can be no more matches. 01256 */ 01257 if (!(name && !namelen)) { 01258 _prev = c; 01259 retries = -1; 01260 } 01261 } 01262 } 01263 AST_RWLIST_UNLOCK(&channels); 01264 if (done) 01265 return c; 01266 /* If we reach this point we basically tried to lock a channel and failed. Instead of 01267 * starting from the beginning of the list we can restore our saved pointer to the previous 01268 * channel and start from there. 01269 */ 01270 prev = _prev; 01271 usleep(1); /* give other threads a chance before retrying */ 01272 } 01273 01274 return NULL; 01275 }
| 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 5925 of file channel.c.
References CHANNEL_CLI_RELOAD, CHANNEL_MODULE_LOAD, and CHANNEL_MODULE_RELOAD.
Referenced by reload_config().
05926 { 05927 switch (reason) { 05928 case CHANNEL_MODULE_LOAD: 05929 return "LOAD (Channel module load)"; 05930 05931 case CHANNEL_MODULE_RELOAD: 05932 return "RELOAD (Channel module reload)"; 05933 05934 case CHANNEL_CLI_RELOAD: 05935 return "CLIRELOAD (Channel module reload by CLI command)"; 05936 05937 default: 05938 return "MANAGERRELOAD (Channel module reload by manager)"; 05939 } 05940 };
| 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 4564 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::name, ast_var_t::value, and ast_channel::varshead.
Referenced by ast_do_masquerade().
04565 { 04566 struct ast_var_t *current, *newvar; 04567 /* Append variables from clone channel into original channel */ 04568 /* XXX Is this always correct? We have to in order to keep MACROS working XXX */ 04569 if (AST_LIST_FIRST(&clonechan->varshead)) 04570 AST_LIST_APPEND_LIST(&original->varshead, &clonechan->varshead, entries); 04571 04572 /* then, dup the varshead list into the clone */ 04573 04574 AST_LIST_TRAVERSE(&original->varshead, current, entries) { 04575 newvar = ast_var_assign(current->name, current->value); 04576 if (newvar) 04577 AST_LIST_INSERT_TAIL(&clonechan->varshead, newvar, entries); 04578 } 04579 }
| static char* complete_channeltypes | ( | struct ast_cli_args * | a | ) | [static] |
Definition at line 246 of file channel.c.
References AST_LIST_TRAVERSE, ast_strdup, 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 1432 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().
01433 { 01434 if (cid->cid_dnid) 01435 ast_free(cid->cid_dnid); 01436 if (cid->cid_num) 01437 ast_free(cid->cid_num); 01438 if (cid->cid_name) 01439 ast_free(cid->cid_name); 01440 if (cid->cid_ani) 01441 ast_free(cid->cid_ani); 01442 if (cid->cid_rdnis) 01443 ast_free(cid->cid_rdnis); 01444 cid->cid_dnid = cid->cid_num = cid->cid_name = cid->cid_ani = cid->cid_rdnis = NULL; 01445 }
| static void free_translation | ( | struct ast_channel * | clonechan | ) | [static] |
Definition at line 1737 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().
01738 { 01739 if (clonechan->writetrans) 01740 ast_translator_free_path(clonechan->writetrans); 01741 if (clonechan->readtrans) 01742 ast_translator_free_path(clonechan->readtrans); 01743 clonechan->writetrans = NULL; 01744 clonechan->readtrans = NULL; 01745 clonechan->rawwriteformat = clonechan->nativeformats; 01746 clonechan->rawreadformat = clonechan->nativeformats; 01747 }
| static int generator_force | ( | const void * | data | ) | [static] |
Definition at line 2031 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_deactivate_generator(), ast_debug, AST_FORMAT_AUDIO_MASK, ast_format_rate(), ast_generator::generate, ast_channel::generator, ast_channel::generatordata, and ast_channel::writeformat.
Referenced by ast_activate_generator(), and ast_read_generator_actions().
02032 { 02033 /* Called if generator doesn't have data */ 02034 void *tmp; 02035 int res; 02036 int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples) = NULL; 02037 struct ast_channel *chan = (struct ast_channel *)data; 02038 02039 ast_channel_lock(chan); 02040 tmp = chan->generatordata; 02041 chan->generatordata = NULL; 02042 if (chan->generator) 02043 generate = chan->generator->generate; 02044 ast_channel_unlock(chan); 02045 02046 if (!tmp || !generate) 02047 return 0; 02048 02049 res = generate(chan, tmp, 0, ast_format_rate(chan->writeformat & AST_FORMAT_AUDIO_MASK) / 50); 02050 02051 chan->generatordata = tmp; 02052 02053 if (res) { 02054 ast_debug(1, "Auto-deactivating generator\n"); 02055 ast_deactivate_generator(chan); 02056 } 02057 02058 return 0; 02059 }
| static void handle_cause | ( | int | cause, | |
| int * | outstate | |||
| ) | [static] |
Definition at line 3964 of file channel.c.
References AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, AST_CONTROL_BUSY, and AST_CONTROL_CONGESTION.
Referenced by __ast_request_and_dial(), and ast_call_forward().
03965 { 03966 if (outstate) { 03967 /* compute error and return */ 03968 if (cause == AST_CAUSE_BUSY) 03969 *outstate = AST_CONTROL_BUSY; 03970 else if (cause == AST_CAUSE_CONGESTION) 03971 *outstate = AST_CONTROL_CONGESTION; 03972 else 03973 *outstate = 0; 03974 } 03975 }
| 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, 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::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 3194 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().
03195 { 03196 /* Don't include a default case here so that we get compiler warnings 03197 * when a new type is added. */ 03198 03199 switch (condition) { 03200 case AST_CONTROL_PROGRESS: 03201 case AST_CONTROL_PROCEEDING: 03202 case AST_CONTROL_VIDUPDATE: 03203 case AST_CONTROL_SRCUPDATE: 03204 case AST_CONTROL_SRCCHANGE: 03205 case AST_CONTROL_RADIO_KEY: 03206 case AST_CONTROL_RADIO_UNKEY: 03207 case AST_CONTROL_OPTION: 03208 case AST_CONTROL_WINK: 03209 case AST_CONTROL_FLASH: 03210 case AST_CONTROL_OFFHOOK: 03211 case AST_CONTROL_TAKEOFFHOOK: 03212 case AST_CONTROL_ANSWER: 03213 case AST_CONTROL_HANGUP: 03214 case AST_CONTROL_T38_PARAMETERS: 03215 case _XXX_AST_CONTROL_T38: 03216 break; 03217 03218 case AST_CONTROL_CONGESTION: 03219 case AST_CONTROL_BUSY: 03220 case AST_CONTROL_RINGING: 03221 case AST_CONTROL_RING: 03222 case AST_CONTROL_HOLD: 03223 case AST_CONTROL_UNHOLD: 03224 return 1; 03225 } 03226 03227 return 0; 03228 }
| 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 5196 of file channel.c.
References ast_channel::cid, ast_callerid::cid_num, EVENT_FLAG_CALL, manager_event, and S_OR.
Referenced by ast_channel_bridge().
05197 { 05198 manager_event(EVENT_FLAG_CALL, "Bridge", 05199 "Bridgestate: %s\r\n" 05200 "Bridgetype: %s\r\n" 05201 "Channel1: %s\r\n" 05202 "Channel2: %s\r\n" 05203 "Uniqueid1: %s\r\n" 05204 "Uniqueid2: %s\r\n" 05205 "CallerID1: %s\r\n" 05206 "CallerID2: %s\r\n", 05207 onoff ? "Link" : "Unlink", 05208 type == 1 ? "core" : "native", 05209 c0->name, c1->name, c0->uniqueid, c1->uniqueid, 05210 S_OR(c0->cid.cid_num, ""), 05211 S_OR(c1->cid.cid_num, "")); 05212 }
| static void plc_ds_destroy | ( | void * | data | ) | [static] |
Definition at line 3506 of file channel.c.
References ast_free, and plc_ds::samples_buf.
03507 { 03508 struct plc_ds *plc = data; 03509 ast_free(plc->samples_buf); 03510 ast_free(plc); 03511 }
| static void queue_dtmf_readq | ( | struct ast_channel * | chan, | |
| struct ast_frame * | f | |||
| ) | [inline, static] |
Definition at line 2641 of file channel.c.
References AST_FRAME_DTMF_END, ast_queue_frame(), ast_channel::dtmff, ast_frame::frametype, ast_frame::len, and ast_frame::subclass.
Referenced by __ast_read().
02642 { 02643 struct ast_frame *fr = &chan->dtmff; 02644 02645 fr->frametype = AST_FRAME_DTMF_END; 02646 fr->subclass = f->subclass; 02647 fr->len = f->len; 02648 02649 /* The only time this function will be called is for a frame that just came 02650 * out of the channel driver. So, we want to stick it on the tail of the 02651 * readq. */ 02652 02653 ast_queue_frame(chan, fr); 02654 }
| static void report_new_callerid | ( | const struct ast_channel * | chan | ) | [static] |
Definition at line 4584 of file channel.c.
References ast_describe_caller_presentation(), ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, ast_callerid::cid_pres, EVENT_FLAG_CALL, manager_event, and S_OR.
Referenced by ast_do_masquerade(), and ast_set_callerid().
04585 { 04586 manager_event(EVENT_FLAG_CALL, "NewCallerid", 04587 "Channel: %s\r\n" 04588 "CallerIDNum: %s\r\n" 04589 "CallerIDName: %s\r\n" 04590 "Uniqueid: %s\r\n" 04591 "CID-CallingPres: %d (%s)\r\n", 04592 chan->name, 04593 S_OR(chan->cid.cid_num, ""), 04594 S_OR(chan->cid.cid_name, ""), 04595 chan->uniqueid, 04596 chan->cid.cid_pres, 04597 ast_describe_caller_presentation(chan->cid.cid_pres) 04598 ); 04599 }
| 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 2580 of file channel.c.
References EVENT_FLAG_DTMF, and manager_event.
Referenced by __ast_read(), and ast_write().
02581 { 02582 manager_event(EVENT_FLAG_DTMF, 02583 "DTMF", 02584 "Channel: %s\r\n" 02585 "Uniqueid: %s\r\n" 02586 "Digit: %c\r\n" 02587 "Direction: %s\r\n" 02588 "Begin: %s\r\n" 02589 "End: %s\r\n", 02590 chan->name, chan->uniqueid, digit, direction, begin, end); 02591 }
| 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 3871 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(), LOG_WARNING, and ast_channel::nativeformats.
Referenced by ast_set_read_format(), and ast_set_write_format().
03873 { 03874 int native; 03875 int res; 03876 char from[200], to[200]; 03877 03878 /* Make sure we only consider audio */ 03879 fmt &= AST_FORMAT_AUDIO_MASK; 03880 03881 native = chan->nativeformats; 03882 03883 if (!fmt || !native) /* No audio requested */ 03884 return 0; /* Let's try a call without any sounds (video, text) */ 03885 03886 /* Find a translation path from the native format to one of the desired formats */ 03887 if (!direction) 03888 /* reading */ 03889 res = ast_translator_best_choice(&fmt, &native); 03890 else 03891 /* writing */ 03892 res = ast_translator_best_choice(&native, &fmt); 03893 03894 if (res < 0) { 03895 ast_log(LOG_WARNING, "Unable to find a codec translation path from %s to %s\n", 03896 ast_getformatname_multiple(from, sizeof(from), native), 03897 ast_getformatname_multiple(to, sizeof(to), fmt)); 03898 return -1; 03899 } 03900 03901 /* Now we have a good choice for both. */ 03902 ast_channel_lock(chan); 03903 03904 if ((*rawformat == native) && (*format == fmt) && ((*rawformat == *format) || (*trans))) { 03905 /* the channel is already in these formats, so nothing to do */ 03906 ast_channel_unlock(chan); 03907 return 0; 03908 } 03909 03910 *rawformat = native; 03911 /* User perspective is fmt */ 03912 *format = fmt; 03913 /* Free any read translation we have right now */ 03914 if (*trans) 03915 ast_translator_free_path(*trans); 03916 /* Build a translation path from the raw format to the desired format */ 03917 if (!direction) 03918 /* reading */ 03919 *trans = ast_translator_build_path(*format, *rawformat); 03920 else 03921 /* writing */ 03922 *trans = ast_translator_build_path(*rawformat, *format); 03923 ast_channel_unlock(chan); 03924 ast_debug(1, "Set channel %s to %s format %s\n", chan->name, 03925 direction ? "write" : "read", ast_getformatname(fmt)); 03926 return 0; 03927 }
| 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 2659 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(), and ast_channel::dtmf_tv.
Referenced by __ast_read().
02660 { 02661 if (ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_EMULATE_DTMF)) { 02662 /* We're in the middle of emulating a digit, or DTMF has been 02663 * explicitly deferred. Skip this digit, then. */ 02664 return 1; 02665 } 02666 02667 if (!ast_tvzero(chan->dtmf_tv) && 02668 ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) { 02669 /* We're not in the middle of a digit, but it hasn't been long enough 02670 * since the last digit, so we'll have to skip DTMF for now. */ 02671 return 1; 02672 } 02673 02674 return 0; 02675 }
| 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 5856 of file channel.c.
References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_write(), and ast_frame::frametype.
05857 { 05858 short buf[samples]; 05859 struct ast_frame frame = { 05860 .frametype = AST_FRAME_VOICE, 05861 .subclass = AST_FORMAT_SLINEAR, 05862 .data.ptr = buf, 05863 .samples = samples, 05864 .datalen = sizeof(buf), 05865 }; 05866 05867 memset(buf, 0, sizeof(buf)); 05868 05869 if (ast_write(chan, &frame)) 05870 return -1; 05871 05872 return 0; 05873 }
| 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 5594 of file channel.c.
References ast_calloc, AST_FLAG_WRITE_INT, AST_FORMAT_SLINEAR, ast_log(), ast_set_flag, ast_set_write_format(), cos, tonepair_def::duration, tonepair_state::duration, tonepair_state::fac1, tonepair_state::fac2, tonepair_def::freq1, tonepair_def::freq2, LOG_WARNING, tonepair_state::modulate, tonepair_state::origwfmt, tonepair_release(), tonepair_state::v1_1, tonepair_state::v2_1, tonepair_state::v2_2, tonepair_state::v3_1, tonepair_state::v3_2, tonepair_def::vol, and ast_channel::writeformat.
05595 { 05596 struct tonepair_state *ts; 05597 struct tonepair_def *td = params; 05598 05599 if (!(ts = ast_calloc(1, sizeof(*ts)))) 05600 return NULL; 05601 ts->origwfmt = chan->writeformat; 05602 if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) { 05603 ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name); 05604 tonepair_release(NULL, ts); 05605 ts = NULL; 05606 } else { 05607 ts->fac1 = 2.0 * cos(2.0 * M_PI * (td->freq1 / 8000.0)) * 32768.0; 05608 ts->v1_1 = 0; 05609 ts->v2_1 = sin(-4.0 * M_PI * (td->freq1 / 8000.0)) * td->vol; 05610 ts->v3_1 = sin(-2.0 * M_PI * (td->freq1 / 8000.0)) * td->vol; 05611 ts->v2_1 = 0; 05612 ts->fac2 = 2.0 * cos(2.0 * M_PI * (td->freq2 / 8000.0)) * 32768.0; 05613 ts->v2_2 = sin(-4.0 * M_PI * (td->freq2 / 8000.0)) * td->vol; 05614 ts->v3_2 = sin(-2.0 * M_PI * (td->freq2 / 8000.0)) * td->vol; 05615 ts->duration = td->duration; 05616 ts->modulate = 0; 05617 } 05618 /* Let interrupts interrupt :) */ 05619 ast_set_flag(chan, AST_FLAG_WRITE_INT); 05620 return ts; 05621 }
| static int tonepair_generator | ( | struct ast_channel * | chan, | |
| void * | data, | |||
| int | len, | |||
| int | samples | |||
| ) | [static] |
Definition at line 5623 of file channel.c.
References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_write(), ast_frame::data, tonepair_state::data, ast_frame::datalen, tonepair_state::duration, tonepair_state::f, tonepair_state::fac1, tonepair_state::fac2, ast_frame::frametype, LOG_WARNING, tonepair_state::modulate, ast_frame::offset, tonepair_state::pos, ast_frame::ptr, ast_frame::samples, ast_frame::subclass, 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.
05624 { 05625 struct tonepair_state *ts = data; 05626 int x; 05627 05628 /* we need to prepare a frame with 16 * timelen samples as we're 05629 * generating SLIN audio 05630 */ 05631 len = samples * 2; 05632 05633 if (len > sizeof(ts->data) / 2 - 1) { 05634 ast_log(LOG_WARNING, "Can't generate that much data!\n"); 05635 return -1; 05636 } 05637 memset(&ts->f, 0, sizeof(ts->f)); 05638 for (x=0;x<len/2;x++) { 05639 ts->v1_1 = ts->v2_1; 05640 ts->v2_1 = ts->v3_1; 05641 ts->v3_1 = (ts->fac1 * ts->v2_1 >> 15) - ts->v1_1; 05642 05643 ts->v1_2 = ts->v2_2; 05644 ts->v2_2 = ts->v3_2; 05645 ts->v3_2 = (ts->fac2 * ts->v2_2 >> 15) - ts->v1_2; 05646 if (ts->modulate) { 05647 int p; 05648 p = ts->v3_2 - 32768; 05649 if (p < 0) p = -p; 05650 p = ((p * 9) / 10) + 1; 05651 ts->data[x] = (ts->v3_1 * p) >> 15; 05652 } else 05653 ts->data[x] = ts->v3_1 + ts->v3_2; 05654 } 05655 ts->f.frametype = AST_FRAME_VOICE; 05656 ts->f.subclass = AST_FORMAT_SLINEAR; 05657 ts->f.datalen = len; 05658 ts->f.samples = samples; 05659 ts->f.offset = AST_FRIENDLY_OFFSET; 05660 ts->f.data.ptr = ts->data; 05661 ast_write(chan, &ts->f); 05662 ts->pos += x; 05663 if (ts->duration > 0) { 05664 if (ts->pos >= ts->duration * 8) 05665 return -1; 05666 } 05667 return 0; 05668 }
| static void tonepair_release | ( | struct ast_channel * | chan, | |
| void * | params | |||
| ) | [static] |
Definition at line 5585 of file channel.c.
References ast_free, ast_set_write_format(), and tonepair_state::origwfmt.
Referenced by tonepair_alloc().
05586 { 05587 struct tonepair_state *ts = params; 05588 05589 if (chan) 05590 ast_set_write_format(chan, ts->origwfmt); 05591 ast_free(ts); 05592 }
| static void update_bridge_vars | ( | struct ast_channel * | c0, | |
| struct ast_channel * | c1 | |||
| ) | [static] |
Definition at line 5214 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_strdupa, ast_strlen_zero(), ast_channel_tech::get_pvt_uniqueid, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), and ast_channel::tech.
Referenced by ast_channel_bridge().
05215 { 05216 const char *c0_name; 05217 const char *c1_name; 05218 const char *c0_pvtid = NULL; 05219 const char *c1_pvtid = NULL; 05220 05221 ast_channel_lock(c1); 05222 c1_name = ast_strdupa(c1->name); 05223 if (c1->tech->get_pvt_uniqueid) { 05224 c1_pvtid = ast_strdupa(c1->tech->get_pvt_uniqueid(c1)); 05225 } 05226 ast_channel_unlock(c1); 05227 05228 ast_channel_lock(c0); 05229 if (!ast_strlen_zero(pbx_builtin_getvar_helper(c0, "BRIDGEPEER"))) { 05230 pbx_builtin_setvar_helper(c0, "BRIDGEPEER", c1_name); 05231 } 05232 if (c1_pvtid) { 05233 pbx_builtin_setvar_helper(c0, "BRIDGEPVTCALLID", c1_pvtid); 05234 } 05235 c0_name = ast_strdupa(c0->name); 05236 if (c0->tech->get_pvt_uniqueid) { 05237 c0_pvtid = ast_strdupa(c0->tech->get_pvt_uniqueid(c0)); 05238 } 05239 ast_channel_unlock(c0); 05240 05241 ast_channel_lock(c1); 05242 if (!ast_strlen_zero(pbx_builtin_getvar_helper(c1, "BRIDGEPEER"))) { 05243 pbx_builtin_setvar_helper(c1, "BRIDGEPEER", c0_name); 05244 } 05245 if (c0_pvtid) { 05246 pbx_builtin_setvar_helper(c1, "BRIDGEPVTCALLID", c0_pvtid); 05247 } 05248 ast_channel_unlock(c1); 05249 }
void(* ast_moh_cleanup_ptr)(struct ast_channel *) = NULL [static] |
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] |
Referenced by ast_install_music_functions(), ast_moh_start(), and ast_uninstall_music_functions().
void(* ast_moh_stop_ptr)(struct ast_channel *) = NULL [static] |
Referenced by ast_install_music_functions(), ast_moh_stop(), and ast_uninstall_music_functions().
| int cause |
Definition at line 136 of file channel.c.
Referenced by __ast_read(), __ast_request_and_dial(), ast_call_forward(), ast_str2cause(), cb_events(), dial_exec_full(), dial_transfer(), do_forward(), dump_cause(), feature_request_and_dial(), oh323_hangup(), ospfinished_exec(), ospnext_exec(), parse_disconnect(), parse_release(), parse_release_complete(), parse_status(), pbx_builtin_hangup(), play_sound_file(), sms_messagerx(), and sms_messagerx2().
struct { ... } causes[] [static] |
map AST_CAUSE's to readable string representations
Referenced by ast_cause2str(), ast_str2cause(), and dump_cause().
struct ast_cli_entry cli_channel[] [static] |
{
AST_CLI_DEFINE(handle_cli_core_show_channeltypes, "List available channel types"),
AST_CLI_DEFINE(handle_cli_core_show_channeltype, "Give more details on that channel type")
}
Definition at line 329 of file channel.c.
Referenced by ast_channels_init().
| const char* desc |
Definition at line 138 of file channel.c.
Referenced by acf_retrieve_docs(), ast_tcptls_client_start(), ast_tcptls_server_root(), dump_cause(), handle_cli_ulimit(), init_acf_query(), load_rpt_vars(), misdn_cfg_get_desc(), show_config_description(), and str2desc().
| 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 |
Definition at line 86 of file channel.c.
Referenced by handle_core_set_debug_channel().
struct ast_channel_tech null_tech [static] |
{
.type = "NULL",
.description = "Null channel (should not see this)",
}
Definition at line 765 of file channel.c.
Referenced by __ast_channel_alloc_ap().
struct ast_datastore_info plc_ds_info [static] |
{
.type = "plc",
.destroy = plc_ds_destroy,
}
Definition at line 3513 of file channel.c.
Referenced by apply_plc().
int shutting_down [static] |
struct ast_generator silence_generator [static] |
{
.alloc = silence_generator_alloc,
.release = silence_generator_release,
.generate = silence_generator_generate,
}
struct ast_threadstorage state2str_threadbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_state2str_threadbuf , .custom_init = NULL , } [static] |
Definition at line 88 of file channel.c.
Referenced by ast_state2str().
struct ast_generator tonepair [static] |
{
alloc: tonepair_alloc,
release: tonepair_release,
generate: tonepair_generator,
}
Definition at line 5670 of file channel.c.
Referenced by ast_tonepair_start().
1.6.1