#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <sys/time.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <math.h>
#include "asterisk/pbx.h"
#include "asterisk/frame.h"
#include "asterisk/sched.h"
#include "asterisk/options.h"
#include "asterisk/channel.h"
#include "asterisk/chanspy.h"
#include "asterisk/musiconhold.h"
#include "asterisk/logger.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 dependency graph for channel.c:

Go to the source code of this file.
Data Structures | |
| struct | ast_cause |
| struct | ast_channel_spy_list |
| struct | ast_channel_whisper_buffer |
| struct | ast_silence_generator |
| struct | chanlist |
| struct | channel_spy_trans |
| 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 | MONITOR_CONSTANT_DELAY |
| #define | MONITOR_DELAY 150 * 8 |
| #define | SPY_QUEUE_SAMPLE_LIMIT 4000 |
| #define | STATE2STR_BUFSIZE 32 |
Enumerations | |
| enum | spy_direction { SPY_READ, SPY_WRITE } |
Functions | |
| static struct ast_frame * | __ast_read (struct ast_channel *chan, int dropaudio) |
| ast_channel * | __ast_request_and_dial (const char *type, int format, void *data, int timeout, int *outstate, const char *cid_num, const char *cid_name, struct outgoing_helper *oh) |
| 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 ringing call. | |
| void | ast_begin_shutdown (int hangup) |
| Initiate system shutdown. | |
| int | ast_best_codec (int fmts) |
| Pick the best audio codec. | |
| ast_channel * | ast_bridged_channel (struct ast_channel *chan) |
| Find bridged channel. | |
| int | ast_call (struct ast_channel *chan, char *addr, int timeout) |
| Make a call. | |
| void | ast_cancel_shutdown (void) |
| Cancel a shutdown in progress. | |
| const char * | ast_cause2str (int cause) |
| Gives the string form of a given hangup cause. | |
| void | ast_change_name (struct ast_channel *chan, char *newname) |
| Change channel name. | |
| ast_channel * | ast_channel_alloc (int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const int amaflag, const char *name_fmt,...) |
| Create a channel structure. | |
| 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_datastore_add (struct ast_channel *chan, struct ast_datastore *datastore) |
| Add a datastore to a channel. | |
| ast_datastore * | ast_channel_datastore_alloc (const struct ast_datastore_info *info, char *uid) |
| Create a channel datastore structure. | |
| ast_datastore * | ast_channel_datastore_find (struct ast_channel *chan, const struct ast_datastore_info *info, char *uid) |
| Find a datastore on a channel. | |
| int | ast_channel_datastore_free (struct ast_datastore *datastore) |
| Free a channel datastore structure. | |
| 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. | |
| 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. | |
| int | ast_channel_masquerade (struct ast_channel *original, struct ast_channel *clone) |
| Weird function made for call transfers. | |
| int | ast_channel_register (const struct ast_channel_tech *tech) |
| Register a channel technology (a new channel driver) Called by a channel module to register the kind of channels it supports. | |
| int | ast_channel_sendhtml (struct ast_channel *chan, int subclass, const char *data, int datalen) |
| int | ast_channel_sendurl (struct ast_channel *chan, const char *url) |
| 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. | |
| int | ast_channel_spy_add (struct ast_channel *chan, struct ast_channel_spy *spy) |
| Adds a spy to a channel, to begin receiving copies of the channel's audio frames. | |
| void | ast_channel_spy_free (struct ast_channel_spy *spy) |
| Free a spy. | |
| ast_frame * | ast_channel_spy_read_frame (struct ast_channel_spy *spy, unsigned int samples) |
| Read one (or more) frames of audio from a channel being spied upon. | |
| void | ast_channel_spy_remove (struct ast_channel *chan, struct ast_channel_spy *spy) |
| Remove a spy from a channel. | |
| void | ast_channel_spy_stop_by_type (struct ast_channel *chan, const char *type) |
| Find all spies of a particular type on a channel and stop them. | |
| void | ast_channel_spy_trigger_wait (struct ast_channel_spy *spy) |
| Efficiently wait until audio is available for a spy, or an exception occurs. | |
| ast_silence_generator * | ast_channel_start_silence_generator (struct ast_channel *chan) |
| Starts a silence generator on the given channel. | |
| void | ast_channel_stop_silence_generator (struct ast_channel *chan, struct ast_silence_generator *state) |
| Stops a previously-started silence generator on the given channel. | |
| int | ast_channel_supports_html (struct ast_channel *chan) |
| void | ast_channel_undefer_dtmf (struct ast_channel *chan) |
| Unset defer DTMF flag on channel. | |
| void | ast_channel_unregister (const struct ast_channel_tech *tech) |
| Unregister a channel technology. | |
| ast_channel * | ast_channel_walk_locked (const struct ast_channel *prev) |
| Browse channels in use Browse the channels currently in use. | |
| int | ast_channel_whisper_feed (struct ast_channel *chan, struct ast_frame *f) |
| Feed an audio frame into the whisper buffer on a channel. | |
| int | ast_channel_whisper_start (struct ast_channel *chan) |
| Begin 'whispering' onto a channel. | |
| void | ast_channel_whisper_stop (struct ast_channel *chan) |
| Stop 'whispering' onto a channel. | |
| void | ast_channels_init (void) |
| ast_variable * | ast_channeltype_list (void) |
| return an ast_variable list of channeltypes | |
| int | ast_check_hangup (struct ast_channel *chan) |
| Check to see if a channel is needing hang up. | |
| static int | ast_check_hangup_locked (struct ast_channel *chan) |
| void | ast_deactivate_generator (struct ast_channel *chan) |
| int | ast_do_masquerade (struct ast_channel *original) |
| Start masquerading a channel XXX This is a seriously wacked out operation. We're essentially putting the guts of the clone channel into the original channel. Start by killing off the original channel's backend. I'm not sure we're going to keep this function, because while the features are nice, the cost is very high in terms of pure nastiness. XXX. | |
| static enum ast_bridge_result | ast_generic_bridge (struct ast_channel *c0, struct ast_channel *c1, struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc, struct timeval bridge_end) |
| ast_channel * | ast_get_channel_by_exten_locked (const char *exten, const char *context) |
| Get channel by exten (and optionally context) and lock it. | |
| ast_channel * | ast_get_channel_by_name_locked (const char *name) |
| Get channel by name (locks channel). | |
| ast_channel * | ast_get_channel_by_name_prefix_locked (const char *name, const int namelen) |
| Get channel by name prefix (locks channel). | |
| ast_channel_tech * | ast_get_channel_tech (const char *name) |
| Get a channel technology structure by name. | |
| ast_group_t | ast_get_group (const char *s) |
| int | ast_hangup (struct ast_channel *chan) |
| Hang up a channel. | |
| int | ast_indicate (struct ast_channel *chan, int condition) |
| Indicates condition of channel. | |
| int | ast_indicate_data (struct ast_channel *chan, int condition, const void *data, size_t datalen) |
| Indicates condition of channel, with payload. | |
| void | ast_install_music_functions (int(*start_ptr)(struct ast_channel *, const char *, const char *), void(*stop_ptr)(struct ast_channel *), void(*cleanup_ptr)(struct ast_channel *)) |
| int | ast_internal_timing_enabled (struct ast_channel *chan) |
| Check if the channel can run in internal timing mode. | |
| static | AST_LIST_HEAD_NOLOCK_STATIC (backends, chanlist) |
| static | AST_LIST_HEAD_STATIC (channels, ast_channel) |
| 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. | |
| char * | ast_print_group (char *buf, int buflen, ast_group_t group) |
| print call- and pickup groups into buffer | |
| int | ast_prod (struct ast_channel *chan) |
| Send empty audio to prime a channel driver. | |
| int | ast_queue_control (struct ast_channel *chan, enum ast_control_frame_type control) |
| Queue a control frame with payload. | |
| int | ast_queue_control_data (struct ast_channel *chan, enum ast_control_frame_type control, const void *data, size_t datalen) |
| Queue a control frame with payload. | |
| int | ast_queue_frame (struct ast_channel *chan, struct ast_frame *fin) |
| Queue an outgoing frame. | |
| int | ast_queue_hangup (struct ast_channel *chan) |
| Queue a hangup frame. | |
| ast_frame * | ast_read (struct ast_channel *chan) |
| Reads a frame. | |
| ast_frame * | ast_read_noaudio (struct ast_channel *chan) |
| Reads a frame, returning AST_FRAME_NULL frame if audio. | |
| int | ast_readstring (struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders) |
| int | ast_readstring_full (struct ast_channel *c, char *s, int len, int timeout, int ftimeout, char *enders, int audiofd, int ctrlfd) |
| int | ast_recvchar (struct ast_channel *chan, int timeout) |
| Receives a text character from a channel. | |
| char * | ast_recvtext (struct ast_channel *chan, int timeout) |
| Receives a text string from a channel Read a string of text from a channel. | |
| ast_channel * | ast_request (const char *type, int format, void *data, int *cause) |
| Requests a channel. | |
| ast_channel * | ast_request_and_dial (const char *type, int format, void *data, int timeout, int *outstate, const char *cidnum, const char *cidname) |
| Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it. | |
| int | ast_safe_sleep (struct ast_channel *chan, int ms) |
| Wait for a specied amount of time, looking for hangups. | |
| int | ast_safe_sleep_conditional (struct ast_channel *chan, int ms, int(*cond)(void *), void *data) |
| Wait for a specied amount of time, looking for hangups and a condition argument. | |
| char * | ast_safe_string_alloc (const char *fmt,...) |
| printf the string into a correctly sized mallocd buffer, and return the buffer | |
| int | ast_say_character_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang) |
| int | ast_say_digit_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang) |
| int | ast_say_digits (struct ast_channel *chan, int num, const char *ints, const char *lang) |
| int | ast_say_digits_full (struct ast_channel *chan, int num, const char *ints, const char *lang, int audiofd, int ctrlfd) |
| int | ast_say_enumeration (struct ast_channel *chan, int num, const char *ints, const char *language, const char *options) |
| int | ast_say_number (struct ast_channel *chan, int num, const char *ints, const char *language, const char *options) |
| int | ast_say_phonetic_str (struct ast_channel *chan, const char *str, const char *ints, const char *lang) |
| int | ast_senddigit (struct ast_channel *chan, char digit) |
| 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 Write text to a display on a channel. | |
| void | ast_set_callerid (struct ast_channel *chan, const char *callerid, const char *calleridname, const char *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 compoent 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, int samples, int(*func)(void *data), void *data) |
| int | ast_shutting_down (void) |
| Returns non-zero if Asterisk is being shut down. | |
| int | ast_softhangup (struct ast_channel *chan, int cause) |
| Softly hangup up a channel. | |
| int | ast_softhangup_nolock (struct ast_channel *chan, int cause) |
| Softly hangup up a channel (no channel lock). | |
| 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. | |
| AST_THREADSTORAGE (state2str_threadbuf, state2str_threadbuf_init) | |
| int | ast_tonepair (struct ast_channel *chan, int freq1, int freq2, int duration, int vol) |
| int | ast_tonepair_start (struct ast_channel *chan, int freq1, int freq2, int duration, int vol) |
| void | ast_tonepair_stop (struct ast_channel *chan) |
| int | ast_transfer (struct ast_channel *chan, char *dest) |
| Transfer a channel (if supported). Returns -1 on error, 0 if not supported and 1 if supported and requested. | |
| char * | ast_transfercapability2str (int transfercapability) |
| Gives the string form of a given transfer capability. | |
| void | ast_uninstall_music_functions (void) |
| int | ast_waitfor (struct ast_channel *c, int ms) |
| Wait for input on a channel. | |
| ast_channel * | ast_waitfor_n (struct ast_channel **c, int n, int *ms) |
| Waits for input on a group of channels Wait for input on an array of channels for a given # of milliseconds. | |
| int | ast_waitfor_n_fd (int *fds, int n, int *ms, int *exception) |
| Waits for input on an fd This version works on fd's only. Be careful with it. | |
| ast_channel * | ast_waitfor_nandfds (struct ast_channel **c, int n, int *fds, int nfds, int *exception, int *outfd, int *ms) |
| Waits for activity on a group of channels. | |
| int | ast_waitfordigit (struct ast_channel *c, int ms) |
| Waits for a digit. | |
| int | ast_waitfordigit_full (struct ast_channel *c, int ms, int audiofd, int cmdfd) |
| Wait for a digit Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading. | |
| ast_channel * | ast_walk_channel_by_exten_locked (const struct ast_channel *chan, const char *exten, const char *context) |
| Get next channel by exten (and optionally context) and lock it. | |
| ast_channel * | ast_walk_channel_by_name_prefix_locked (const struct ast_channel *chan, const char *name, const int namelen) |
| Get channel by name prefix (locks channel). | |
| int | ast_write (struct ast_channel *chan, struct ast_frame *fr) |
| Write a frame to a channel This function writes the given frame to the indicated channel. | |
| int | ast_write_video (struct ast_channel *chan, struct ast_frame *fr) |
| Write video frame to a channel This function writes the given frame to the indicated channel. | |
| static void | bridge_playfile (struct ast_channel *chan, struct ast_channel *peer, const char *sound, int remain) |
| 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 *clone) |
| Clone channel variables from 'clone' channel into 'original' channel. | |
| static char * | complete_channeltypes (const char *line, const char *word, int pos, int state) |
| static char * | complete_channeltypes_deprecated (const char *line, const char *word, int pos, int state) |
| static void | copy_data_from_queue (struct ast_channel_spy_queue *queue, short *buf, unsigned int samples) |
| static void | detach_spies (struct ast_channel *chan) |
| static void | free_cid (struct ast_callerid *cid) |
| static void | free_translation (struct ast_channel *clone) |
| static int | generator_force (void *data) |
| static void | queue_frame_to_spies (struct ast_channel *chan, struct ast_frame *f, enum spy_direction dir) |
| static int | set_format (struct ast_channel *chan, int fmt, int *rawformat, int *format, struct ast_trans_pvt **trans, const int direction) |
| static int | show_channeltype (int fd, int argc, char *argv[]) |
| static int | show_channeltype_deprecated (int fd, int argc, char *argv[]) |
| static int | show_channeltypes (int fd, int argc, char *argv[]) |
| 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 | spy_cleanup (struct ast_channel *chan) |
| static void | spy_detach (struct ast_channel_spy *spy, struct ast_channel *chan) |
| 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) |
Variables | |
| static void(*) | ast_moh_cleanup_ptr (struct ast_channel *) = NULL |
| static int(*) | ast_moh_start_ptr (struct ast_channel *, const char *, const char *) = NULL |
| static void(*) | ast_moh_stop_ptr (struct ast_channel *) = NULL |
| ast_cause | causes [] |
| static struct ast_cli_entry | cli_channel [] |
| static struct ast_cli_entry | cli_show_channeltype_deprecated |
| static struct ast_cli_entry | cli_show_channeltypes_deprecated |
| unsigned long | global_fin |
| unsigned long | global_fout |
| static struct ast_channel_tech | null_tech |
| static char | show_channeltype_usage [] |
| static char | show_channeltypes_usage [] |
| static int | shutting_down |
| static struct ast_generator | silence_generator |
| static struct ast_generator | tonepair |
| static int | uniqueint |
Definition in file channel.c.
| #define AST_DEFAULT_EMULATE_DTMF_DURATION 100 |
Default amount of time to use when emulating a digit as a begin and end 100ms
Definition at line 107 of file channel.c.
Referenced by __ast_read().
| #define AST_MIN_DTMF_DURATION 80 |
Minimum allowed digit length - 80ms
Definition at line 110 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 114 of file channel.c.
Referenced by __ast_read().
| #define FORMAT "%-10.10s %-40.40s %-12.12s %-12.12s %-12.12s\n" |
| #define MONITOR_DELAY 150 * 8 |
| #define SPY_QUEUE_SAMPLE_LIMIT 4000 |
| #define STATE2STR_BUFSIZE 32 |
| enum spy_direction |
| static struct ast_frame* __ast_read | ( | struct ast_channel * | chan, | |
| int | dropaudio | |||
| ) | [static] |
Definition at line 2097 of file channel.c.
References ast_channel::_softhangup, ast_channel::_state, ast_channel::alertpipe, ast_cdr_alloc(), ast_cdr_answer(), ast_cdr_end(), ast_cdr_init(), ast_cdr_start(), ast_channel_lock, ast_channel_unlock, ast_check_hangup(), ast_clear_flag, AST_CONTROL_ANSWER, AST_CONTROL_HANGUP, ast_deactivate_generator(), 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_FRAME_CNG, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, ast_frame_dump(), AST_FRAME_VOICE, ast_frfree(), AST_GENERATOR_FD, ast_getformatname(), ast_internal_timing_enabled(), AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_HEAD_SET_NOLOCK, AST_LIST_NEXT, AST_LIST_REMOVE_HEAD, ast_log(), AST_MIN_DTMF_DURATION, AST_MIN_DTMF_GAP, AST_MONITOR_RUNNING, ast_null_frame, ast_seekstream(), ast_set_flag, ast_setstate(), ast_settimeout(), AST_SOFTHANGUP_DEV, AST_STATE_UP, ast_strlen_zero(), ast_test_flag, AST_TIMING_FD, ast_translate(), ast_writestream(), ast_channel::blocker, ast_channel::cdr, ast_frame::data, DEBUGCHAN_FLAG, ast_channel::dtmf_tv, ast_channel::dtmff, ast_channel::dtmfq, ast_channel::emulate_dtmf_digit, ast_channel::emulate_dtmf_duration, ast_channel_tech::exception, f, ast_channel::fdno, ast_channel::fds, ast_channel::fin, FRAMECOUNT_INC, ast_frame::frametype, func, ast_generator::generate, ast_channel::generator, generator_force(), ast_channel::generatordata, ast_channel::insmpl, LOG_DEBUG, LOG_DTMF, LOG_NOTICE, LOG_WARNING, ast_channel::masq, ast_channel::monitor, MONITOR_DELAY, ast_channel::nativeformats, option_debug, ast_channel::outsmpl, queue_frame_to_spies(), ast_channel_tech::read, ast_channel_monitor::read_stream, ast_channel::readtrans, SEEK_FORCECUR, ast_channel::spies, SPY_READ, ast_channel_monitor::state, ast_frame::subclass, ast_channel::tech, ast_channel::timingdata, ast_channel::timingfd, and ast_channel::timingfunc.
Referenced by ast_read(), and ast_read_noaudio().
02098 { 02099 struct ast_frame *f = NULL; /* the return value */ 02100 int blah; 02101 int prestate; 02102 02103 /* this function is very long so make sure there is only one return 02104 * point at the end (there is only one exception to this). 02105 */ 02106 ast_channel_lock(chan); 02107 if (chan->masq) { 02108 if (ast_do_masquerade(chan)) 02109 ast_log(LOG_WARNING, "Failed to perform masquerade\n"); 02110 else 02111 f = &ast_null_frame; 02112 goto done; 02113 } 02114 02115 /* Stop if we're a zombie or need a soft hangup */ 02116 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 02117 if (chan->generator) 02118 ast_deactivate_generator(chan); 02119 goto done; 02120 } 02121 prestate = chan->_state; 02122 02123 if (!ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_EMULATE_DTMF | AST_FLAG_IN_DTMF) && 02124 !ast_strlen_zero(chan->dtmfq) && 02125 (ast_tvzero(chan->dtmf_tv) || ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) > AST_MIN_DTMF_GAP) ) { 02126 /* We have DTMF that has been deferred. Return it now */ 02127 chan->dtmff.subclass = chan->dtmfq[0]; 02128 /* Drop first digit from the buffer */ 02129 memmove(chan->dtmfq, chan->dtmfq + 1, sizeof(chan->dtmfq) - 1); 02130 f = &chan->dtmff; 02131 if (ast_test_flag(chan, AST_FLAG_END_DTMF_ONLY)) 02132 chan->dtmff.frametype = AST_FRAME_DTMF_END; 02133 else { 02134 chan->dtmff.frametype = AST_FRAME_DTMF_BEGIN; 02135 ast_set_flag(chan, AST_FLAG_EMULATE_DTMF); 02136 chan->emulate_dtmf_digit = f->subclass; 02137 chan->emulate_dtmf_duration = AST_DEFAULT_EMULATE_DTMF_DURATION; 02138 } 02139 chan->dtmf_tv = ast_tvnow(); 02140 goto done; 02141 } 02142 02143 /* Read and ignore anything on the alertpipe, but read only 02144 one sizeof(blah) per frame that we send from it */ 02145 if (chan->alertpipe[0] > -1) 02146 read(chan->alertpipe[0], &blah, sizeof(blah)); 02147 02148 #ifdef HAVE_ZAPTEL 02149 if (chan->timingfd > -1 && chan->fdno == AST_TIMING_FD && ast_test_flag(chan, AST_FLAG_EXCEPTION)) { 02150 int res; 02151 02152 ast_clear_flag(chan, AST_FLAG_EXCEPTION); 02153 blah = -1; 02154 /* IF we can't get event, assume it's an expired as-per the old interface */ 02155 res = ioctl(chan->timingfd, ZT_GETEVENT, &blah); 02156 if (res) 02157 blah = ZT_EVENT_TIMER_EXPIRED; 02158 02159 if (blah == ZT_EVENT_TIMER_PING) { 02160 if (AST_LIST_EMPTY(&chan->readq) || !AST_LIST_NEXT(AST_LIST_FIRST(&chan->readq), frame_list)) { 02161 /* Acknowledge PONG unless we need it again */ 02162 if (ioctl(chan->timingfd, ZT_TIMERPONG, &blah)) { 02163 ast_log(LOG_WARNING, "Failed to pong timer on '%s': %s\n", chan->name, strerror(errno)); 02164 } 02165 } 02166 } else if (blah == ZT_EVENT_TIMER_EXPIRED) { 02167 ioctl(chan->timingfd, ZT_TIMERACK, &blah); 02168 if (chan->timingfunc) { 02169 /* save a copy of func/data before unlocking the channel */ 02170 int (*func)(void *) = chan->timingfunc; 02171 void *data = chan->timingdata; 02172 ast_channel_unlock(chan); 02173 func(data); 02174 } else { 02175 blah = 0; 02176 ioctl(chan->timingfd, ZT_TIMERCONFIG, &blah); 02177 chan->timingdata = NULL; 02178 ast_channel_unlock(chan); 02179 } 02180 /* cannot 'goto done' because the channel is already unlocked */ 02181 return &ast_null_frame; 02182 } else 02183 ast_log(LOG_NOTICE, "No/unknown event '%d' on timer for '%s'?\n", blah, chan->name); 02184 } else 02185 #endif 02186 if (chan->fds[AST_GENERATOR_FD] > -1 && chan->fdno == AST_GENERATOR_FD) { 02187 /* if the AST_GENERATOR_FD is set, call the generator with args 02188 * set to -1 so it can do whatever it needs to. 02189 */ 02190 void *tmp = chan->generatordata; 02191 chan->generatordata = NULL; /* reset to let ast_write get through */ 02192 chan->generator->generate(chan, tmp, -1, -1); 02193 chan->generatordata = tmp; 02194 f = &ast_null_frame; 02195 goto done; 02196 } 02197 02198 /* Check for pending read queue */ 02199 if (!AST_LIST_EMPTY(&chan->readq)) { 02200 f = AST_LIST_REMOVE_HEAD(&chan->readq, frame_list); 02201 /* Interpret hangup and return NULL */ 02202 /* XXX why not the same for frames from the channel ? */ 02203 if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) { 02204 ast_frfree(f); 02205 f = NULL; 02206 } 02207 } else { 02208 chan->blocker = pthread_self(); 02209 if (ast_test_flag(chan, AST_FLAG_EXCEPTION)) { 02210 if (chan->tech->exception) 02211 f = chan->tech->exception(chan); 02212 else { 02213 ast_log(LOG_WARNING, "Exception flag set on '%s', but no exception handler\n", chan->name); 02214 f = &ast_null_frame; 02215 } 02216 /* Clear the exception flag */ 02217 ast_clear_flag(chan, AST_FLAG_EXCEPTION); 02218 } else if (chan->tech->read) 02219 f = chan->tech->read(chan); 02220 else 02221 ast_log(LOG_WARNING, "No read routine on channel %s\n", chan->name); 02222 } 02223 02224 if (f) { 02225 /* if the channel driver returned more than one frame, stuff the excess 02226 into the readq for the next ast_read call (note that we can safely assume 02227 that the readq is empty, because otherwise we would not have called into 02228 the channel driver and f would be only a single frame) 02229 */ 02230 if (AST_LIST_NEXT(f, frame_list)) { 02231 AST_LIST_HEAD_SET_NOLOCK(&chan->readq, AST_LIST_NEXT(f, frame_list)); 02232 AST_LIST_NEXT(f, frame_list) = NULL; 02233 } 02234 02235 switch (f->frametype) { 02236 case AST_FRAME_CONTROL: 02237 if (f->subclass == AST_CONTROL_ANSWER) { 02238 if (!ast_test_flag(chan, AST_FLAG_OUTGOING)) { 02239 if (option_debug) 02240 ast_log(LOG_DEBUG, "Ignoring answer on an inbound call!\n"); 02241 ast_frfree(f); 02242 f = &ast_null_frame; 02243 } else if (prestate == AST_STATE_UP) { 02244 if (option_debug) 02245 ast_log(LOG_DEBUG, "Dropping duplicate answer!\n"); 02246 ast_frfree(f); 02247 f = &ast_null_frame; 02248 } else { 02249 /* Answer the CDR */ 02250 ast_setstate(chan, AST_STATE_UP); 02251 if (!chan->cdr) { /* up till now, this insertion hasn't been done. Therefore, 02252 to keep from throwing off the basic order of the universe, 02253 we will try to keep this cdr from getting posted. */ 02254 chan->cdr = ast_cdr_alloc(); 02255 ast_cdr_init(chan->cdr, chan); 02256 ast_cdr_start(chan->cdr); 02257 } 02258 02259 ast_cdr_answer(chan->cdr); 02260 } 02261 } 02262 break; 02263 case AST_FRAME_DTMF_END: 02264 ast_log(LOG_DTMF, "DTMF end '%c' received on %s, duration %ld ms\n", f->subclass, chan->name, f->len); 02265 /* Queue it up if DTMF is deffered, or if DTMF emulation is forced. 02266 * However, only let emulation be forced if the other end cares about BEGIN frames */ 02267 if ( ast_test_flag(chan, AST_FLAG_DEFER_DTMF) || 02268 (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF) && !ast_test_flag(chan, AST_FLAG_END_DTMF_ONLY)) ) { 02269 if (strlen(chan->dtmfq) < sizeof(chan->dtmfq) - 2) 02270 chan->dtmfq[strlen(chan->dtmfq)] = f->subclass; 02271 else 02272 ast_log(LOG_WARNING, "Dropping deferred DTMF digits on %s\n", chan->name); 02273 ast_frfree(f); 02274 f = &ast_null_frame; 02275 } else if (!ast_test_flag(chan, AST_FLAG_IN_DTMF | AST_FLAG_END_DTMF_ONLY)) { 02276 if (!ast_tvzero(chan->dtmf_tv) && 02277 ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) { 02278 /* If it hasn't been long enough, defer this digit */ 02279 if (strlen(chan->dtmfq) < sizeof(chan->dtmfq) - 2) 02280 chan->dtmfq[strlen(chan->dtmfq)] = f->subclass; 02281 else 02282 ast_log(LOG_WARNING, "Dropping deferred DTMF digits on %s\n", chan->name); 02283 ast_frfree(f); 02284 f = &ast_null_frame; 02285 } else { 02286 /* There was no begin, turn this into a begin and send the end later */ 02287 f->frametype = AST_FRAME_DTMF_BEGIN; 02288 ast_set_flag(chan, AST_FLAG_EMULATE_DTMF); 02289 chan->emulate_dtmf_digit = f->subclass; 02290 chan->dtmf_tv = ast_tvnow(); 02291 if (f->len && f->len > AST_MIN_DTMF_DURATION) 02292 chan->emulate_dtmf_duration = f->len; 02293 else 02294 chan->emulate_dtmf_duration = AST_MIN_DTMF_DURATION; 02295 } 02296 } else { 02297 struct timeval now = ast_tvnow(); 02298 ast_clear_flag(chan, AST_FLAG_IN_DTMF); 02299 if (!f->len) 02300 f->len = ast_tvdiff_ms(now, chan->dtmf_tv); 02301 if (f->len < AST_MIN_DTMF_DURATION) { 02302 ast_set_flag(chan, AST_FLAG_EMULATE_DTMF); 02303 chan->emulate_dtmf_digit = f->subclass; 02304 chan->emulate_dtmf_duration = AST_MIN_DTMF_DURATION - f->len; 02305 f = &ast_null_frame; 02306 } else 02307 chan->dtmf_tv = now; 02308 } 02309 break; 02310 case AST_FRAME_DTMF_BEGIN: 02311 ast_log(LOG_DTMF, "DTMF begin '%c' received on %s\n", f->subclass, chan->name); 02312 if ( ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_END_DTMF_ONLY) || 02313 (!ast_tvzero(chan->dtmf_tv) && 02314 ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) < AST_MIN_DTMF_GAP) ) { 02315 ast_frfree(f); 02316 f = &ast_null_frame; 02317 } else { 02318 ast_set_flag(chan, AST_FLAG_IN_DTMF); 02319 chan->dtmf_tv = ast_tvnow(); 02320 } 02321 break; 02322 case AST_FRAME_VOICE: 02323 /* The EMULATE_DTMF flag must be cleared here as opposed to when the samples 02324 * first get to zero, because we want to make sure we pass at least one 02325 * voice frame through before starting the next digit, to ensure a gap 02326 * between DTMF digits. */ 02327 if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF) && !chan->emulate_dtmf_duration) { 02328 ast_clear_flag(chan, AST_FLAG_EMULATE_DTMF); 02329 chan->emulate_dtmf_digit = 0; 02330 } 02331 02332 if (dropaudio || ast_test_flag(chan, AST_FLAG_IN_DTMF)) { 02333 ast_frfree(f); 02334 f = &ast_null_frame; 02335 } else if (ast_test_flag(chan, AST_FLAG_EMULATE_DTMF)) { 02336 if ((f->samples / 8) >= chan->emulate_dtmf_duration) { /* XXX 8kHz */ 02337 struct timeval now = ast_tvnow(); 02338 chan->emulate_dtmf_duration = 0; 02339 f->frametype = AST_FRAME_DTMF_END; 02340 f->subclass = chan->emulate_dtmf_digit; 02341 f->len = ast_tvdiff_ms(now, chan->dtmf_tv); 02342 chan->dtmf_tv = now; 02343 } else { 02344 chan->emulate_dtmf_duration -= f->samples / 8; /* XXX 8kHz */ 02345 ast_frfree(f); 02346 f = &ast_null_frame; 02347 } 02348 } else if (!(f->subclass & chan->nativeformats)) { 02349 /* This frame can't be from the current native formats -- drop it on the 02350 floor */ 02351 ast_log(LOG_NOTICE, "Dropping incompatible voice frame on %s of format %s since our native format has changed to %s\n", 02352 chan->name, ast_getformatname(f->subclass), ast_getformatname(chan->nativeformats)); 02353 ast_frame_dump(chan->name, f, "<<"); 02354 ast_frfree(f); 02355 f = &ast_null_frame; 02356 } else { 02357 if (chan->spies) 02358 queue_frame_to_spies(chan, f, SPY_READ); 02359 02360 if (chan->monitor && chan->monitor->read_stream ) { 02361 /* XXX what does this do ? */ 02362 #ifndef MONITOR_CONSTANT_DELAY 02363 int jump = chan->outsmpl - chan->insmpl - 4 * f->samples; 02364 if (jump >= 0) { 02365 jump = chan->outsmpl - chan->insmpl; 02366 if (ast_seekstream(chan->monitor->read_stream, jump, SEEK_FORCECUR) == -1) 02367 ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n"); 02368 chan->insmpl += jump + f->samples; 02369 } else 02370 chan->insmpl+= f->samples; 02371 #else 02372 int jump = chan->outsmpl - chan->insmpl; 02373 if (jump - MONITOR_DELAY >= 0) { 02374 if (ast_seekstream(chan->monitor->read_stream, jump - f->samples, SEEK_FORCECUR) == -1) 02375 ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n"); 02376 chan->insmpl += jump; 02377 } else 02378 chan->insmpl += f->samples; 02379 #endif 02380 if (chan->monitor->state == AST_MONITOR_RUNNING) { 02381 if (ast_writestream(chan->monitor->read_stream, f) < 0) 02382 ast_log(LOG_WARNING, "Failed to write data to channel monitor read stream\n"); 02383 } 02384 } 02385 02386 if (chan->readtrans && (f = ast_translate(chan->readtrans, f, 1)) == NULL) 02387 f = &ast_null_frame; 02388 02389 /* Run generator sitting on the line if timing device not available 02390 * and synchronous generation of outgoing frames is necessary */ 02391 if (chan->generatordata && !ast_internal_timing_enabled(chan)) { 02392 void *tmp = chan->generatordata; 02393 int res; 02394 02395 if (chan->timingfunc) { 02396 if (option_debug > 1) 02397 ast_log(LOG_DEBUG, "Generator got voice, switching to phase locked mode\n"); 02398 ast_settimeout(chan, 0, NULL, NULL); 02399 } 02400 02401 chan->generatordata = NULL; /* reset, to let writes go through */ 02402 res = chan->generator->generate(chan, tmp, f->datalen, f->samples); 02403 chan->generatordata = tmp; 02404 if (res) { 02405 if (option_debug > 1) 02406 ast_log(LOG_DEBUG, "Auto-deactivating generator\n"); 02407 ast_deactivate_generator(chan); 02408 } 02409 02410 } else if (f->frametype == AST_FRAME_CNG) { 02411 if (chan->generator && !chan->timingfunc && (chan->timingfd > -1)) { 02412 if (option_debug > 1) 02413 ast_log(LOG_DEBUG, "Generator got CNG, switching to timed mode\n"); 02414 ast_settimeout(chan, 160, generator_force, chan); 02415 } 02416 } 02417 } 02418 default: 02419 /* Just pass it on! */ 02420 break; 02421 } 02422 } else { 02423 /* Make sure we always return NULL in the future */ 02424 chan->_softhangup |= AST_SOFTHANGUP_DEV; 02425 if (chan->generator) 02426 ast_deactivate_generator(chan); 02427 /* End the CDR if appropriate */ 02428 if (chan->cdr) 02429 ast_cdr_end(chan->cdr); 02430 } 02431 02432 /* High bit prints debugging */ 02433 if (chan->fin & DEBUGCHAN_FLAG) 02434 ast_frame_dump(chan->name, f, "<<"); 02435 chan->fin = FRAMECOUNT_INC(chan->fin); 02436 02437 done: 02438 ast_channel_unlock(chan); 02439 return f; 02440 }
| 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 | |||
| ) |
Definition at line 2927 of file channel.c.
References ast_channel::_state, outgoing_helper::account, ast_call(), AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, ast_cdr_alloc(), ast_cdr_disposition(), ast_cdr_end(), ast_cdr_failed(), ast_cdr_init(), ast_cdr_setaccount(), ast_cdr_setapp(), ast_cdr_start(), ast_cdr_update(), 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_UNHOLD, AST_CONTROL_VIDUPDATE, AST_FRAME_CONTROL, ast_frfree(), ast_hangup(), ast_log(), ast_read(), ast_request(), ast_set_callerid(), ast_set_variables(), AST_STATE_UP, ast_strlen_zero(), ast_waitfor(), ast_channel::cdr, outgoing_helper::cid_name, outgoing_helper::cid_num, outgoing_helper::context, ast_channel::context, outgoing_helper::exten, ast_channel::exten, f, ast_channel::hangupcause, LOG_NOTICE, outgoing_helper::parent_channel, outgoing_helper::priority, ast_channel::priority, and outgoing_helper::vars.
Referenced by ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_request_and_dial(), and parkandannounce_exec().
02928 { 02929 int dummy_outstate; 02930 int cause = 0; 02931 struct ast_channel *chan; 02932 int res = 0; 02933 02934 if (outstate) 02935 *outstate = 0; 02936 else 02937 outstate = &dummy_outstate; /* make outstate always a valid pointer */ 02938 02939 chan = ast_request(type, format, data, &cause); 02940 if (!chan) { 02941 ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data); 02942 /* compute error and return */ 02943 if (cause == AST_CAUSE_BUSY) 02944 *outstate = AST_CONTROL_BUSY; 02945 else if (cause == AST_CAUSE_CONGESTION) 02946 *outstate = AST_CONTROL_CONGESTION; 02947 return NULL; 02948 } 02949 02950 if (oh) { 02951 if (oh->vars) 02952 ast_set_variables(chan, oh->vars); 02953 /* XXX why is this necessary, for the parent_channel perhaps ? */ 02954 if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) 02955 ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num); 02956 if (oh->parent_channel) 02957 ast_channel_inherit_variables(oh->parent_channel, chan); 02958 if (oh->account) 02959 ast_cdr_setaccount(chan, oh->account); 02960 } 02961 ast_set_callerid(chan, cid_num, cid_name, cid_num); 02962 02963 02964 02965 if (!chan->cdr) { /* up till now, this insertion hasn't been done. Therefore, 02966 to keep from throwing off the basic order of the universe, 02967 we will try to keep this cdr from getting posted. */ 02968 chan->cdr = ast_cdr_alloc(); 02969 ast_cdr_init(chan->cdr, chan); 02970 ast_cdr_start(chan->cdr); 02971 } 02972 if (ast_call(chan, data, 0)) { /* ast_call failed... */ 02973 ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data); 02974 } else { 02975 res = 1; /* mark success in case chan->_state is already AST_STATE_UP */ 02976 while (timeout && chan->_state != AST_STATE_UP) { 02977 struct ast_frame *f; 02978 res = ast_waitfor(chan, timeout); 02979 if (res <= 0) /* error, timeout, or done */ 02980 break; 02981 if (timeout > -1) 02982 timeout = res; 02983 f = ast_read(chan); 02984 if (!f) { 02985 *outstate = AST_CONTROL_HANGUP; 02986 res = 0; 02987 break; 02988 } 02989 if (f->frametype == AST_FRAME_CONTROL) { 02990 switch (f->subclass) { 02991 case AST_CONTROL_RINGING: /* record but keep going */ 02992 *outstate = f->subclass; 02993 break; 02994 02995 case AST_CONTROL_BUSY: 02996 case AST_CONTROL_CONGESTION: 02997 case AST_CONTROL_ANSWER: 02998 *outstate = f->subclass; 02999 timeout = 0; /* trick to force exit from the while() */ 03000 break; 03001 03002 /* Ignore these */ 03003 case AST_CONTROL_PROGRESS: 03004 case AST_CONTROL_PROCEEDING: 03005 case AST_CONTROL_HOLD: 03006 case AST_CONTROL_UNHOLD: 03007 case AST_CONTROL_VIDUPDATE: 03008 case -1: /* Ignore -- just stopping indications */ 03009 break; 03010 03011 default: 03012 ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass); 03013 } 03014 } 03015 ast_frfree(f); 03016 } 03017 } 03018 03019 /* Final fixups */ 03020 if (oh) { 03021 if (!ast_strlen_zero(oh->context)) 03022 ast_copy_string(chan->context, oh->context, sizeof(chan->context)); 03023 if (!ast_strlen_zero(oh->exten)) 03024 ast_copy_string(chan->exten, oh->exten, sizeof(chan->exten)); 03025 if (oh->priority) 03026 chan->priority = oh->priority; 03027 } 03028 if (chan->_state == AST_STATE_UP) 03029 *outstate = AST_CONTROL_ANSWER; 03030 03031 if (res <= 0) { 03032 if (!chan->cdr && (chan->cdr = ast_cdr_alloc())) 03033 ast_cdr_init(chan->cdr, chan); 03034 if (chan->cdr) { 03035 char tmp[256]; 03036 snprintf(tmp, sizeof(tmp), "%s/%s", type, (char *)data); 03037 ast_cdr_setapp(chan->cdr,"Dial",tmp); 03038 ast_cdr_update(chan); 03039 ast_cdr_start(chan->cdr); 03040 ast_cdr_end(chan->cdr); 03041 /* If the cause wasn't handled properly */ 03042 if (ast_cdr_disposition(chan->cdr,chan->hangupcause)) 03043 ast_cdr_failed(chan->cdr); 03044 } 03045 ast_hangup(chan); 03046 chan = NULL; 03047 } 03048 return chan; 03049 }
| int ast_activate_generator | ( | struct ast_channel * | chan, | |
| struct ast_generator * | gen, | |||
| void * | params | |||
| ) |
Activate a given generator
Definition at line 1814 of file channel.c.
References ast_generator::alloc, ast_channel_lock, ast_channel_unlock, ast_prod(), ast_settimeout(), gen, ast_channel::generator, generator_force(), ast_channel::generatordata, and ast_generator::release.
Referenced by app_exec(), ast_channel_start_silence_generator(), ast_linear_stream(), ast_playtones_start(), ast_tonepair_start(), channel_spy(), local_ast_moh_start(), and milliwatt_exec().
01815 { 01816 int res = 0; 01817 01818 ast_channel_lock(chan); 01819 01820 if (chan->generatordata) { 01821 if (chan->generator && chan->generator->release) 01822 chan->generator->release(chan, chan->generatordata); 01823 chan->generatordata = NULL; 01824 } 01825 01826 ast_prod(chan); 01827 if (gen->alloc && !(chan->generatordata = gen->alloc(chan, params))) { 01828 res = -1; 01829 } 01830 01831 if (!res) { 01832 ast_settimeout(chan, 160, generator_force, chan); 01833 chan->generator = gen; 01834 } 01835 01836 ast_channel_unlock(chan); 01837 01838 return res; 01839 }
| int ast_active_channels | ( | void | ) |
returns number of active/allocated channels
Returns number of active/allocated channels
Definition at line 454 of file channel.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, and AST_LIST_UNLOCK.
Referenced by quit_handler().
00455 { 00456 struct ast_channel *c; 00457 int cnt = 0; 00458 AST_LIST_LOCK(&channels); 00459 AST_LIST_TRAVERSE(&channels, c, chan_list) 00460 cnt++; 00461 AST_LIST_UNLOCK(&channels); 00462 return cnt; 00463 }
| int ast_answer | ( | struct ast_channel * | chan | ) |
Answer a ringing call.
| chan | channel to answer This function answers a channel and handles all necessary call setup functions. |
Definition at line 1747 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_setstate(), AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_test_flag, ast_channel::cdr, and ast_channel::tech.
Referenced by __login_exec(), agi_exec_full(), alarmreceiver_exec(), app_exec(), ast_bridge_call(), ast_control_streamfile(), ast_pickup_call(), auth_exec(), background_detect_exec(), builtin_parkcall(), common_exec(), conf_exec(), count_exec(), dictate_exec(), directory_exec(), disa_exec(), features_answer(), handle_answer(), ices_exec(), milliwatt_exec(), mwanalyze_exec(), nv_background_detect_exec(), nv_detectfax_exec(), park_call_exec(), park_exec(), pbx_builtin_answer(), pbx_builtin_background(), pickup_do(), playback_exec(), privacy_exec(), read_exec(), rpt_exec(), run_station(), rxfax_exec(), sayunixtime_exec(), send_waveform_to_channel(), skel_exec(), sla_handle_dial_state_event(), sla_station_exec(), speech_background(), testclient_exec(), testserver_exec(), txfax_exec(), vm_exec(), vm_execmain(), waitforsilence_exec(), zapateller_exec(), and zapras_exec().
01748 { 01749 int res = 0; 01750 ast_channel_lock(chan); 01751 /* You can't answer an outbound call */ 01752 if (ast_test_flag(chan, AST_FLAG_OUTGOING)) { 01753 ast_channel_unlock(chan); 01754 return 0; 01755 } 01756 /* Stop if we're a zombie or need a soft hangup */ 01757 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 01758 ast_channel_unlock(chan); 01759 return -1; 01760 } 01761 switch(chan->_state) { 01762 case AST_STATE_RINGING: 01763 case AST_STATE_RING: 01764 if (chan->tech->answer) 01765 res = chan->tech->answer(chan); 01766 ast_setstate(chan, AST_STATE_UP); 01767 ast_cdr_answer(chan->cdr); 01768 break; 01769 case AST_STATE_UP: 01770 ast_cdr_answer(chan->cdr); 01771 break; 01772 default: 01773 break; 01774 } 01775 ast_channel_unlock(chan); 01776 return res; 01777 }
| 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 441 of file channel.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_softhangup(), AST_SOFTHANGUP_SHUTDOWN, and shutting_down.
Referenced by quit_handler().
00442 { 00443 struct ast_channel *c; 00444 shutting_down = 1; 00445 if (hangup) { 00446 AST_LIST_LOCK(&channels); 00447 AST_LIST_TRAVERSE(&channels, c, chan_list) 00448 ast_softhangup(c, AST_SOFTHANGUP_SHUTDOWN); 00449 AST_LIST_UNLOCK(&channels); 00450 } 00451 }
| int ast_best_codec | ( | int | fmts | ) |
Pick the best audio codec.
Pick the best codec
G.722 is better then all codecs in this list
alaw used by all telephone equipment at Russia
Okay, well, signed linear is easy to translate into other stuff! slinear<->alaw recoding very fast
ulaw standart for USA and Japan
Speex is free, but computationally more expensive than GSM
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
G.729a is faster than 723 and slightly less expensive
Down to G.723.1 which is proprietary but at least designed for voice
Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough to use it
Definition at line 666 of file channel.c.
References AST_FORMAT_ADPCM, AST_FORMAT_ALAW, AST_FORMAT_AUDIO_MASK, AST_FORMAT_G722, AST_FORMAT_G723_1, AST_FORMAT_G726, AST_FORMAT_G726_AAL2, AST_FORMAT_G729A, AST_FORMAT_GSM, AST_FORMAT_ILBC, AST_FORMAT_LPC10, AST_FORMAT_SLINEAR, AST_FORMAT_SPEEX, AST_FORMAT_ULAW, ast_log(), LOG_WARNING, and prefs.
Referenced by __login_exec(), __oh323_new(), agent_call(), ast_channel_best_codec(), ast_codec_choose(), ast_iax2_new(), builtin_atxfer(), echo_exec(), findmeexec(), gtalk_new(), handle_open_receive_channel_ack_message(), iax2_request(), local_new(), mgcp_new(), sip_new(), skinny_new(), socket_process(), and transmit_connect().
00667 { 00668 /* This just our opinion, expressed in code. We are asked to choose 00669 the best codec to use, given no information */ 00670 int x; 00671 static int prefs[] = 00672 { 00673 /*! G.722 is better then all codecs in this list */ 00674 AST_FORMAT_G722, 00675 /*! alaw used by all telephone equipment at Russia */ 00676 AST_FORMAT_ALAW, 00677 /*! Okay, well, signed linear is easy to translate into other stuff! slinear<->alaw recoding very fast */ 00678 AST_FORMAT_SLINEAR, 00679 /*! ulaw standart for USA and Japan */ 00680 AST_FORMAT_ULAW, 00681 /*! Speex is free, but computationally more expensive than GSM */ 00682 AST_FORMAT_SPEEX, 00683 /*! G.726 is standard ADPCM, in RFC3551 packing order */ 00684 AST_FORMAT_G726, 00685 /*! G.726 is standard ADPCM, in AAL2 packing order */ 00686 AST_FORMAT_G726_AAL2, 00687 /*! ADPCM has great sound quality and is still pretty easy to translate */ 00688 AST_FORMAT_ADPCM, 00689 /*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to 00690 translate and sounds pretty good */ 00691 AST_FORMAT_GSM, 00692 /*! iLBC is not too bad */ 00693 AST_FORMAT_ILBC, 00694 /*! G.729a is faster than 723 and slightly less expensive */ 00695 AST_FORMAT_G729A, 00696 /*! Down to G.723.1 which is proprietary but at least designed for voice */ 00697 AST_FORMAT_G723_1, 00698 /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough 00699 to use it */ 00700 AST_FORMAT_LPC10, 00701 }; 00702 00703 /* Strip out video */ 00704 fmts &= AST_FORMAT_AUDIO_MASK; 00705 00706 /* Find the first preferred codec in the format given */ 00707 for (x=0; x < (sizeof(prefs) / sizeof(prefs[0]) ); x++) 00708 if (fmts & prefs[x]) 00709 return prefs[x]; 00710 ast_log(LOG_WARNING, "Don't know any of 0x%x formats\n", fmts); 00711 return 0; 00712 }
| struct ast_channel* ast_bridged_channel | ( | struct ast_channel * | chan | ) |
Find bridged channel.
| chan | Current channel |
Definition at line 3748 of file channel.c.
References ast_channel::_bridge, ast_channel_tech::bridged_channel, and ast_channel::tech.
Referenced by __zt_exception(), agents_show(), agents_show_online(), ast_channel_masquerade(), attempt_transfer(), check_bridge(), common_exec(), console_transfer(), console_transfer_deprecated(), create_jb(), export_aoc_vars(), handle_chanlist(), handle_chanlist_deprecated(), handle_hd_hf(), handle_invite_replaces(), handle_request(), handle_request_bye(), handle_request_info(), handle_request_invite(), handle_request_refer(), handle_response_invite(), handle_showchan(), handle_showchan_deprecated(), local_attended_transfer(), mgcp_hangup(), mgcp_ss(), misdn_transfer_bc(), mixmonitor_thread(), schedule_delivery(), sip_read(), socket_process(), ss_thread(), start_spying(), startmon(), zt_handle_event(), and zt_hangup().
03749 { 03750 struct ast_channel *bridged; 03751 bridged = chan->_bridge; 03752 if (bridged && bridged->tech->bridged_channel) 03753 bridged = bridged->tech->bridged_channel(chan, bridged); 03754 return bridged; 03755 }
| 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 3105 of file channel.c.
References 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, and ast_channel::tech.
Referenced by __ast_request_and_dial(), agent_call(), ast_feature_request_and_dial(), attempt_reconnect(), begin_dial(), features_call(), findmeexec(), function_ilink(), ring_entry(), rpt(), rpt_exec(), and wait_for_answer().
03106 { 03107 /* Place an outgoing call, but don't wait any longer than timeout ms before returning. 03108 If the remote end does not answer within the timeout, then do NOT hang up, but 03109 return anyway. */ 03110 int res = -1; 03111 /* Stop if we're a zombie or need a soft hangup */ 03112 ast_channel_lock(chan); 03113 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) { 03114 if (chan->tech->call) 03115 res = chan->tech->call(chan, addr, timeout); 03116 ast_set_flag(chan, AST_FLAG_OUTGOING); 03117 } 03118 ast_channel_unlock(chan); 03119 return res; 03120 }
| void ast_cancel_shutdown | ( | void | ) |
Cancel a shutdown in progress.
Cancels an existing shutdown and returns to normal operation
Definition at line 466 of file channel.c.
References shutting_down.
Referenced by handle_abort_halt().
00467 { 00468 shutting_down = 0; 00469 }
| const char* ast_cause2str | ( | int | state | ) |
Gives the string form of a given hangup cause.
| state | cause to get the description of Give a name to a cause code Returns the text form of the binary cause code given |
Definition at line 586 of file channel.c.
Referenced by __transmit_response(), ast_hangup(), findmeexec(), and transmit_request_with_auth().
00587 { 00588 int x; 00589 00590 for (x=0; x < sizeof(causes) / sizeof(causes[0]); x++) { 00591 if (causes[x].cause == cause) 00592 return causes[x].desc; 00593 } 00594 00595 return "Unknown"; 00596 }
| void ast_change_name | ( | struct ast_channel * | chan, | |
| char * | newname | |||
| ) |
Change channel name.
Definition at line 3332 of file channel.c.
References ast_string_field_set, EVENT_FLAG_CALL, manager_event(), and name.
03333 { 03334 manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", chan->name, newname, chan->uniqueid); 03335 ast_string_field_set(chan, name, newname); 03336 }
| 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, | |||
| ... | ||||
| ) |
Create a channel structure.
Definition at line 720 of file channel.c.
References ast_calloc, ast_log(), AST_MAX_FDS, ast_string_field_init, free, HAVE_ZAPTEL, LOG_WARNING, sched_context_create(), and shutting_down.
Referenced by __oh323_new(), agent_new(), alsa_new(), ast_async_goto(), ast_iax2_new(), ast_masq_park_call(), ast_pbx_outgoing_cdr_failed(), ast_pbx_outgoing_exten(), builtin_atxfer(), check_goto_on_transfer(), features_new(), gtalk_new(), iax_park(), local_new(), make_email_file(), mgcp_new(), misdn_new(), nbs_new(), oss_new(), pbx_substitute_variables_helper_full(), phone_new(), sendpage(), sip_new(), sip_park(), skinny_new(), and zt_new().
00721 { 00722 struct ast_channel *tmp; 00723 int x; 00724 int flags; 00725 struct varshead *headp; 00726 va_list ap1, ap2; 00727 00728 /* If shutting down, don't allocate any new channels */ 00729 if (shutting_down) { 00730 ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n"); 00731 return NULL; 00732 } 00733 00734 if (!(tmp = ast_calloc(1, sizeof(*tmp)))) 00735 return NULL; 00736 00737 if (!(tmp->sched = sched_context_create())) { 00738 ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n"); 00739 free(tmp); 00740 return NULL; 00741 } 00742 00743 ast_string_field_init(tmp, 128); 00744 00745 /* Don't bother initializing the last two FD here, because they 00746 will *always* be set just a few lines down (AST_TIMING_FD, 00747 AST_ALERT_FD). */ 00748 for (x = 0; x < AST_MAX_FDS - 2; x++) 00749 tmp->fds[x] = -1; 00750 00751 #ifdef HAVE_ZAPTEL 00752 tmp->timingfd = open("/dev/zap/timer", O_RDWR); 00753 if (tmp->timingfd > -1) { 00754 /* Check if timing interface supports new 00755 ping/pong scheme */ 00756 flags = 1; 00757 if (!ioctl(tmp->timingfd, ZT_TIMERPONG, &flags)) 00758 needqueue = 0; 00759 } 00760 #else 00761 tmp->timingfd = -1; 00762 #endif 00763 00764 if (needqueue) { 00765 if (pipe(tmp->alertpipe)) { 00766 ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe!\n"); 00767 ast_string_field_free_pools(tmp); 00768 free(tmp); 00769 return NULL; 00770 } else { 00771 flags = fcntl(tmp->alertpipe[0], F_GETFL); 00772 fcntl(tmp->alertpipe[0], F_SETFL, flags | O_NONBLOCK); 00773 flags = fcntl(tmp->alertpipe[1], F_GETFL); 00774 fcntl(tmp->alertpipe[1], F_SETFL, flags | O_NONBLOCK); 00775 } 00776 } else /* Make sure we've got it done right if they don't */ 00777 tmp->alertpipe[0] = tmp->alertpipe[1] = -1; 00778 00779 /* Always watch the alertpipe */ 00780 tmp->fds[AST_ALERT_FD] = tmp->alertpipe[0]; 00781 /* And timing pipe */ 00782 tmp->fds[AST_TIMING_FD] = tmp->timingfd; 00783 ast_string_field_set(tmp, name, "**Unknown**"); 00784 00785 /* Initial state */ 00786 tmp->_state = state; 00787 00788 tmp->streamid = -1; 00789 00790 tmp->fin = global_fin; 00791 tmp->fout = global_fout; 00792 00793 if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) { 00794 ast_string_field_build(tmp, uniqueid, "%li.%d", (long) time(NULL), 00795 ast_atomic_fetchadd_int(&uniqueint, 1)); 00796 } else { 00797 ast_string_field_build(tmp, uniqueid, "%s-%li.%d", ast_config_AST_SYSTEM_NAME, 00798 (long) time(NULL), ast_atomic_fetchadd_int(&uniqueint, 1)); 00799 } 00800 00801 if (!ast_strlen_zero(name_fmt)) { 00802 /* Almost every channel is calling this function, and setting the name via the ast_string_field_build() call. 00803 * And they all use slightly different formats for their name string. 00804 * This means, to set the name here, we have to accept variable args, and call the string_field_build from here. 00805 * This means, that the stringfields must have a routine that takes the va_lists directly, and 00806 * uses them to build the string, instead of forming the va_lists internally from the vararg ... list. 00807 * This new function was written so this can be accomplished. 00808 */ 00809 va_start(ap1, name_fmt); 00810 va_start(ap2, name_fmt); 00811 ast_string_field_build_va(tmp, name, name_fmt, ap1, ap2); 00812 va_end(ap1); 00813 va_end(ap2); 00814 00815 /* and now, since the channel structure is built, and has its name, let's call the 00816 * manager event generator with this Newchannel event. This is the proper and correct 00817 * place to make this call, but you sure do have to pass a lot of data into this func 00818 * to do it here! 00819 */ 00820 manager_event(EVENT_FLAG_CALL, "Newchannel", 00821 "Channel: %s\r\n" 00822 "State: %s\r\n" 00823 "CallerIDNum: %s\r\n" 00824 "CallerIDName: %s\r\n" 00825 "Uniqueid: %s\r\n", 00826 tmp->name, ast_state2str(state), 00827 S_OR(cid_num, "<unknown>"), 00828 S_OR(cid_name, "<unknown>"), 00829 tmp->uniqueid); 00830 } 00831 00832 /* Reminder for the future: under what conditions do we NOT want to track cdrs on channels? */ 00833 00834 /* These 4 variables need to be set up for the cdr_init() to work right */ 00835 if (amaflag) 00836 tmp->amaflags = amaflag; 00837 else 00838 tmp->amaflags = ast_default_amaflags; 00839 00840 if (!ast_strlen_zero(acctcode)) 00841 ast_string_field_set(tmp, accountcode, acctcode); 00842 else 00843 ast_string_field_set(tmp, accountcode, ast_default_accountcode); 00844 00845 if (!ast_strlen_zero(context)) 00846 ast_copy_string(tmp->context, context, sizeof(tmp->context)); 00847 else 00848 strcpy(tmp->context, "default"); 00849 00850 if (!ast_strlen_zero(exten)) 00851 ast_copy_string(tmp->exten, exten, sizeof(tmp->exten)); 00852 else 00853 strcpy(tmp->exten, "s"); 00854 00855 tmp->priority = 1; 00856 00857 tmp->cdr = ast_cdr_alloc(); 00858 ast_cdr_init(tmp->cdr, tmp); 00859 ast_cdr_start(tmp->cdr); 00860 00861 headp = &tmp->varshead; 00862 AST_LIST_HEAD_INIT_NOLOCK(headp); 00863 00864 ast_mutex_init(&tmp->lock); 00865 00866 AST_LIST_HEAD_INIT_NOLOCK(&tmp->datastores); 00867 00868 ast_string_field_set(tmp, language, defaultlanguage); 00869 00870 tmp->tech = &null_tech; 00871 00872 AST_LIST_LOCK(&channels); 00873 AST_LIST_INSERT_HEAD(&channels, tmp, chan_list); 00874 AST_LIST_UNLOCK(&channels); 00875 00876 return tmp; 00877 }
| 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 3937 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_FEATURE_PLAY_WARNING, AST_FEATURE_REDIRECT, AST_FLAG_END_DTMF_ONLY, AST_FLAG_NBRIDGE, AST_FLAG_ZOMBIE, ast_generic_bridge(), ast_log(), ast_set_flag, AST_SOFTHANGUP_UNBRIDGE, ast_test_flag, ast_tvadd(), ast_tvsub(), ast_verbose(), ast_channel_tech::bridge, bridge_playfile(), ast_channel::cid, ast_callerid::cid_num, config, EVENT_FLAG_CALL, ast_channel::generator, LOG_DEBUG, LOG_WARNING, manager_event(), ast_channel::monitor, ast_channel::nativeformats, option_verbose, ast_channel::readformat, ast_channel_tech::send_digit_begin, ast_channel::spies, t, ast_channel::tech, VERBOSE_PREFIX_3, and ast_channel::writeformat.
Referenced by ast_bridge_call().
03939 { 03940 struct ast_channel *who = NULL; 03941 enum ast_bridge_result res = AST_BRIDGE_COMPLETE; 03942 int nativefailed=0; 03943 int firstpass; 03944 int o0nativeformats; 03945 int o1nativeformats; 03946 long time_left_ms=0; 03947 struct timeval nexteventts = { 0, }; 03948 char caller_warning = 0; 03949 char callee_warning = 0; 03950 03951 if (c0->_bridge) { 03952 ast_log(LOG_WARNING, "%s is already in a bridge with %s\n", 03953 c0->name, c0->_bridge->name); 03954 return -1; 03955 } 03956 if (c1->_bridge) { 03957 ast_log(LOG_WARNING, "%s is already in a bridge with %s\n", 03958 c1->name, c1->_bridge->name); 03959 return -1; 03960 } 03961 03962 /* Stop if we're a zombie or need a soft hangup */ 03963 if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || 03964 ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) 03965 return -1; 03966 03967 *fo = NULL; 03968 firstpass = config->firstpass; 03969 config->firstpass = 0; 03970 03971 if (ast_tvzero(config->start_time)) 03972 config->start_time = ast_tvnow(); 03973 time_left_ms = config->timelimit; 03974 03975 caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING); 03976 callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING); 03977 03978 if (config->start_sound && firstpass) { 03979 if (caller_warning) 03980 bridge_playfile(c0, c1, config->start_sound, time_left_ms / 1000); 03981 if (callee_warning) 03982 bridge_playfile(c1, c0, config->start_sound, time_left_ms / 1000); 03983 } 03984 03985 /* Keep track of bridge */ 03986 c0->_bridge = c1; 03987 c1->_bridge = c0; 03988 03989 /* \todo XXX here should check that cid_num is not NULL */ 03990 manager_event(EVENT_FLAG_CALL, "Link", 03991 "Channel1: %s\r\n" 03992 "Channel2: %s\r\n" 03993 "Uniqueid1: %s\r\n" 03994 "Uniqueid2: %s\r\n" 03995 "CallerID1: %s\r\n" 03996 "CallerID2: %s\r\n", 03997 c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); 03998 03999 o0nativeformats = c0->nativeformats; 04000 o1nativeformats = c1->nativeformats; 04001 04002 if (config->feature_timer) { 04003 nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->feature_timer, 1000)); 04004 } else if (config->timelimit) { 04005 nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000)); 04006 if (caller_warning || callee_warning) 04007 nexteventts = ast_tvsub(nexteventts, ast_samp2tv(config->play_warning, 1000)); 04008 } 04009 04010 if (!c0->tech->send_digit_begin) 04011 ast_set_flag(c1, AST_FLAG_END_DTMF_ONLY); 04012 if (!c1->tech->send_digit_begin) 04013 ast_set_flag(c0, AST_FLAG_END_DTMF_ONLY); 04014 04015 for (/* ever */;;) { 04016 struct timeval now = { 0, }; 04017 int to; 04018 04019 to = -1; 04020 04021 if (!ast_tvzero(nexteventts)) { 04022 now = ast_tvnow(); 04023 to = ast_tvdiff_ms(nexteventts, now); 04024 if (to <= 0) { 04025 if (!config->timelimit) { 04026 res = AST_BRIDGE_COMPLETE; 04027 break; 04028 } 04029 to = 0; 04030 } 04031 } 04032 04033 if (config->timelimit) { 04034 time_left_ms = config->timelimit - ast_tvdiff_ms(now, config->start_time); 04035 if (time_left_ms < to) 04036 to = time_left_ms; 04037 04038 if (time_left_ms <= 0) { 04039 if (caller_warning && config->end_sound) 04040 bridge_playfile(c0, c1, config->end_sound, 0); 04041 if (callee_warning && config->end_sound) 04042 bridge_playfile(c1, c0, config->end_sound, 0); 04043 *fo = NULL; 04044 if (who) 04045 *rc = who; 04046 res = 0; 04047 break; 04048 } 04049 04050 if (!to) { 04051 if (time_left_ms >= 5000 && config->warning_sound && config->play_warning) { 04052 int t = (time_left_ms + 500) / 1000; /* round to nearest second */ 04053 if (caller_warning) 04054 bridge_playfile(c0, c1, config->warning_sound, t); 04055 if (callee_warning) 04056 bridge_playfile(c1, c0, config->warning_sound, t); 04057 } 04058 if (config->warning_freq && (time_left_ms > (config->warning_freq + 5000))) 04059 nexteventts = ast_tvadd(nexteventts, ast_samp2tv(config->warning_freq, 1000)); 04060 else 04061 nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000)); 04062 } 04063 } 04064 04065 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) { 04066 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 04067 c0->_softhangup = 0; 04068 if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 04069 c1->_softhangup = 0; 04070 c0->_bridge = c1; 04071 c1->_bridge = c0; 04072 if (option_debug) 04073 ast_log(LOG_DEBUG, "Unbridge signal received. Ending native bridge.\n"); 04074 continue; 04075 } 04076 04077 /* Stop if we're a zombie or need a soft hangup */ 04078 if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || 04079 ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) { 04080 *fo = NULL; 04081 if (who) 04082 *rc = who; 04083 res = 0; 04084 if (option_debug) 04085 ast_log(LOG_DEBUG, "Bridge stops because we're zombie or need a soft hangup: c0=%s, c1=%s, flags: %s,%s,%s,%s\n", 04086 c0->name, c1->name, 04087 ast_test_flag(c0, AST_FLAG_ZOMBIE) ? "Yes" : "No", 04088 ast_check_hangup(c0) ? "Yes" : "No", 04089 ast_test_flag(c1, AST_FLAG_ZOMBIE) ? "Yes" : "No", 04090 ast_check_hangup(c1) ? "Yes" : "No"); 04091 break; 04092 } 04093 04094 if (c0->tech->bridge && 04095 (config->timelimit == 0) && 04096 (c0->tech->bridge == c1->tech->bridge) && 04097 !nativefailed && !c0->monitor && !c1->monitor && 04098 !c0->spies && !c1->spies && !ast_test_flag(&(config->features_callee),AST_FEATURE_REDIRECT) && 04099 !ast_test_flag(&(config->features_caller),AST_FEATURE_REDIRECT) ) { 04100 /* Looks like they share a bridge method and nothing else is in the way */ 04101 ast_set_flag(c0, AST_FLAG_NBRIDGE); 04102 ast_set_flag(c1, AST_FLAG_NBRIDGE); 04103 if ((res = c0->tech->bridge(c0, c1, config->flags, fo, rc, to)) == AST_BRIDGE_COMPLETE) { 04104 /* \todo XXX here should check that cid_num is not NULL */ 04105 manager_event(EVENT_FLAG_CALL, "Unlink", 04106 "Channel1: %s\r\n" 04107 "Channel2: %s\r\n" 04108 "Uniqueid1: %s\r\n" 04109 "Uniqueid2: %s\r\n" 04110 "CallerID1: %s\r\n" 04111 "CallerID2: %s\r\n", 04112 c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); 04113 if (option_debug) 04114 ast_log(LOG_DEBUG, "Returning from native bridge, channels: %s, %s\n", c0->name, c1->name); 04115 04116 ast_clear_flag(c0, AST_FLAG_NBRIDGE); 04117 ast_clear_flag(c1, AST_FLAG_NBRIDGE); 04118 04119 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 04120 continue; 04121 04122 c0->_bridge = NULL; 04123 c1->_bridge = NULL; 04124 04125 return res; 04126 } else { 04127 ast_clear_flag(c0, AST_FLAG_NBRIDGE); 04128 ast_clear_flag(c1, AST_FLAG_NBRIDGE); 04129 } 04130 switch (res) { 04131 case AST_BRIDGE_RETRY: 04132 continue; 04133 default: 04134 if (option_verbose > 2) 04135 ast_verbose(VERBOSE_PREFIX_3 "Native bridging %s and %s ended\n", 04136 c0->name, c1->name); 04137 /* fallthrough */ 04138 case AST_BRIDGE_FAILED_NOWARN: 04139 nativefailed++; 04140 break; 04141 } 04142 } 04143 04144 if (((c0->writeformat != c1->readformat) || (c0->readformat != c1->writeformat) || 04145 (c0->nativeformats != o0nativeformats) || (c1->nativeformats != o1nativeformats)) && 04146 !(c0->generator || c1->generator)) { 04147 if (ast_channel_make_compatible(c0, c1)) { 04148 ast_log(LOG_WARNING, "Can't make %s and %s compatible\n", c0->name, c1->name); 04149 /* \todo XXX here should check that cid_num is not NULL */ 04150 manager_event(EVENT_FLAG_CALL, "Unlink", 04151 "Channel1: %s\r\n" 04152 "Channel2: %s\r\n" 04153 "Uniqueid1: %s\r\n" 04154 "Uniqueid2: %s\r\n" 04155 "CallerID1: %s\r\n" 04156 "CallerID2: %s\r\n", 04157 c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); 04158 return AST_BRIDGE_FAILED; 04159 } 04160 o0nativeformats = c0->nativeformats; 04161 o1nativeformats = c1->nativeformats; 04162 } 04163 res = ast_generic_bridge(c0, c1, config, fo, rc, nexteventts); 04164 if (res != AST_BRIDGE_RETRY) 04165 break; 04166 } 04167 04168 ast_clear_flag(c0, AST_FLAG_END_DTMF_ONLY); 04169 ast_clear_flag(c1, AST_FLAG_END_DTMF_ONLY); 04170 04171 c0->_bridge = NULL; 04172 c1->_bridge = NULL; 04173 04174 /* \todo XXX here should check that cid_num is not NULL */ 04175 manager_event(EVENT_FLAG_CALL, "Unlink", 04176 "Channel1: %s\r\n" 04177 "Channel2: %s\r\n" 04178 "Uniqueid1: %s\r\n" 04179 "Uniqueid2: %s\r\n" 04180 "CallerID1: %s\r\n" 04181 "CallerID2: %s\r\n", 04182 c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num); 04183 if (option_debug) 04184 ast_log(LOG_DEBUG, "Bridge stops bridging channels %s and %s\n", c0->name, c1->name); 04185 04186 return res; 04187 }
| 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 486 of file channel.c.
References ast_channel::whentohangup.
00487 { 00488 time_t whentohangup; 00489 00490 if (chan->whentohangup == 0) { 00491 return (offset == 0) ? 0 : -1; 00492 } else { 00493 if (offset == 0) /* XXX why is this special ? */ 00494 return (1); 00495 else { 00496 whentohangup = offset + time (NULL); 00497 if (chan->whentohangup < whentohangup) 00498 return (1); 00499 else if (chan->whentohangup == whentohangup) 00500 return (0); 00501 else 00502 return (-1); 00503 } 00504 } 00505 }
| int ast_channel_datastore_add | ( | struct ast_channel * | chan, | |
| struct ast_datastore * | datastore | |||
| ) |
Add a datastore to a channel.
Definition at line 1278 of file channel.c.
References AST_LIST_INSERT_HEAD.
Referenced by speech_create().
01279 { 01280 int res = 0; 01281 01282 AST_LIST_INSERT_HEAD(&chan->datastores, datastore, entry); 01283 01284 return res; 01285 }
| struct ast_datastore* ast_channel_datastore_alloc | ( | const struct ast_datastore_info * | info, | |
| char * | uid | |||
| ) |
Create a channel datastore structure.
Definition at line 1234 of file channel.c.
References ast_calloc, ast_strdup, and ast_datastore::info.
Referenced by speech_create().
01235 { 01236 struct ast_datastore *datastore = NULL; 01237 01238 /* Make sure we at least have type so we can identify this */ 01239 if (info == NULL) { 01240 return NULL; 01241 } 01242 01243 /* Allocate memory for datastore and clear it */ 01244 datastore = ast_calloc(1, sizeof(*datastore)); 01245 if (datastore == NULL) { 01246 return NULL; 01247 } 01248 01249 datastore->info = info; 01250 01251 datastore->uid = ast_strdup(uid); 01252 01253 return datastore; 01254 }
| struct ast_datastore* ast_channel_datastore_find | ( | struct ast_channel * | chan, | |
| const struct ast_datastore_info * | info, | |||
| char * | uid | |||
| ) |
Find a datastore on a channel.
Definition at line 1305 of file channel.c.
References AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_datastore::info, and ast_datastore::uid.
Referenced by find_speech(), speech_background(), and speech_destroy().
01306 { 01307 struct ast_datastore *datastore = NULL; 01308 01309 if (info == NULL) 01310 return NULL; 01311 01312 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore, entry) { 01313 if (datastore->info == info) { 01314 if (uid != NULL && datastore->uid != NULL) { 01315 if (!strcasecmp(uid, datastore->uid)) { 01316 /* Matched by type AND uid */ 01317 break; 01318 } 01319 } else { 01320 /* Matched by type at least */ 01321 break; 01322 } 01323 } 01324 } 01325 AST_LIST_TRAVERSE_SAFE_END 01326 01327 return datastore; 01328 }
| int ast_channel_datastore_free | ( | struct ast_datastore * | datastore | ) |
Free a channel datastore structure.
Definition at line 1256 of file channel.c.
References ast_datastore::data, ast_datastore_info::destroy, free, ast_datastore::info, and ast_datastore::uid.
Referenced by ast_channel_free().
01257 { 01258 int res = 0; 01259 01260 /* Using the destroy function (if present) destroy the data */ 01261 if (datastore->info->destroy != NULL && datastore->data != NULL) { 01262 datastore->info->destroy(datastore->data); 01263 datastore->data = NULL; 01264 } 01265 01266 /* Free allocated UID memory */ 01267 if (datastore->uid != NULL) { 01268 free(datastore->uid); 01269 datastore->uid = NULL; 01270 } 01271 01272 /* Finally free memory used by ourselves */ 01273 free(datastore); 01274 01275 return res; 01276 }
| int ast_channel_datastore_remove | ( | struct ast_channel * | chan, | |
| struct ast_datastore * | datastore | |||
| ) |
Remove a datastore from a channel.
Definition at line 1287 of file channel.c.
References AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, and AST_LIST_TRAVERSE_SAFE_END.
Referenced by speech_background(), and speech_destroy().
01288 { 01289 struct ast_datastore *datastore2 = NULL; 01290 int res = -1; 01291 01292 /* Find our position and remove ourselves */ 01293 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore2, entry) { 01294 if (datastore2 == datastore) { 01295 AST_LIST_REMOVE_CURRENT(&chan->datastores, entry); 01296 res = 0; 01297 break; 01298 } 01299 } 01300 AST_LIST_TRAVERSE_SAFE_END 01301 01302 return res; 01303 }
| int ast_channel_defer_dtmf | ( | struct ast_channel * | chan | ) |
Set defer DTMF flag on channel.
Defer DTMF so that you only read things like hangups and audio. Returns non-zero if channel was already DTMF-deferred or 0 if channel is just now being DTMF-deferred
Definition at line 971 of file channel.c.
References AST_FLAG_DEFER_DTMF, ast_set_flag, and ast_test_flag.
Referenced by __adsi_transmit_messages(), and find_cache().
00972 { 00973 int pre = 0; 00974 00975 if (chan) { 00976 pre = ast_test_flag(chan, AST_FLAG_DEFER_DTMF); 00977 ast_set_flag(chan, AST_FLAG_DEFER_DTMF); 00978 } 00979 return pre; 00980 }
| void ast_channel_free | ( | struct ast_channel * | chan | ) |
Free a channel structure.
Definition at line 1152 of file channel.c.
References ast_channel::alertpipe, ast_app_group_discard(), ast_channel_datastore_free(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_unlock, ast_channel_whisper_stop(), ast_device_state_changed_literal(), ast_frfree(), ast_jb_destroy(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_log(), ast_moh_cleanup(), ast_mutex_destroy(), ast_string_field_free_pools, ast_translator_free_path(), ast_var_delete(), ast_channel::cid, f, free, free_cid(), ast_channel::lock, 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::timingfd, ast_channel::varshead, ast_channel::whisper, and ast_channel::writetrans.
Referenced by agent_cleanup(), agent_new(), ast_hangup(), ast_pbx_outgoing_cdr_failed(), local_new(), make_email_file(), pbx_substitute_variables_helper_full(), and sendpage().
01153 { 01154 int fd; 01155 struct ast_var_t *vardata; 01156 struct ast_frame *f; 01157 struct varshead *headp; 01158 struct ast_datastore *datastore = NULL; 01159 char name[AST_CHANNEL_NAME]; 01160 01161 headp=&chan->varshead; 01162 01163 AST_LIST_LOCK(&channels); 01164 AST_LIST_REMOVE(&channels, chan, chan_list); 01165 /* Lock and unlock the channel just to be sure nobody 01166 has it locked still */ 01167 ast_channel_lock(chan); 01168 ast_channel_unlock(chan); 01169 if (chan->tech_pvt) { 01170 ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name); 01171 free(chan->tech_pvt); 01172 } 01173 01174 if (chan->sched) 01175 sched_context_destroy(chan->sched); 01176 01177 ast_copy_string(name, chan->name, sizeof(name)); 01178 01179 /* Stop monitoring */ 01180 if (chan->monitor) 01181 chan->monitor->stop( chan, 0 ); 01182 01183 /* If there is native format music-on-hold state, free it */ 01184 if (chan->music_state) 01185 ast_moh_cleanup(chan); 01186 01187 /* if someone is whispering on the channel, stop them */ 01188 if (chan->whisper) 01189 ast_channel_whisper_stop(chan); 01190 01191 /* Free translators */ 01192 if (chan->readtrans) 01193 ast_translator_free_path(chan->readtrans); 01194 if (chan->writetrans) 01195 ast_translator_free_path(chan->writetrans); 01196 if (chan->pbx) 01197 ast_log(LOG_WARNING, "PBX may not have been terminated properly on '%s'\n", chan->name); 01198 free_cid(&chan->cid); 01199 ast_mutex_destroy(&chan->lock); 01200 /* Close pipes if appropriate */ 01201 if ((fd = chan->alertpipe[0]) > -1) 01202 close(fd); 01203 if ((fd = chan->alertpipe[1]) > -1) 01204 close(fd); 01205 if ((fd = chan->timingfd) > -1) 01206 close(fd); 01207 while ((f = AST_LIST_REMOVE_HEAD(&chan->readq, frame_list))) 01208 ast_frfree(f); 01209 01210 /* Get rid of each of the data stores on the channel */ 01211 while ((datastore = AST_LIST_REMOVE_HEAD(&chan->datastores, entry))) 01212 /* Free the data store */ 01213 ast_channel_datastore_free(datastore); 01214 AST_LIST_HEAD_INIT_NOLOCK(&chan->datastores); 01215 01216 /* loop over the variables list, freeing all data and deleting list items */ 01217 /* no need to lock the list, as the channel is already locked */ 01218 01219 while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries))) 01220 ast_var_delete(vardata); 01221 01222 ast_app_group_discard(chan); 01223 01224 /* Destroy the jitterbuffer */ 01225 ast_jb_destroy(chan); 01226 01227 ast_string_field_free_pools(chan); 01228 free(chan); 01229 AST_LIST_UNLOCK(&channels); 01230 01231 ast_device_state_changed_literal(name); 01232 }
| void ast_channel_inherit_variables | ( | const struct ast_channel * | parent, | |
| struct ast_channel * | child | |||
| ) |
Inherits channel variable from parent to child channel.
| parent | Parent channel | |
| child | Child channel |
Definition at line 3338 of file channel.c.
References AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log(), ast_var_assign(), ast_var_full_name(), ast_var_name(), ast_var_value(), LOG_DEBUG, option_debug, and ast_channel::varshead.
Referenced by __ast_request_and_dial(), agent_call(), ast_feature_request_and_dial(), begin_dial(), findmeexec(), ring_entry(), and wait_for_answer().
03339 { 03340 struct ast_var_t *current, *newvar; 03341 const char *varname; 03342 03343 AST_LIST_TRAVERSE(&parent->varshead, current, entries) { 03344 int vartype = 0; 03345 03346 varname = ast_var_full_name(current); 03347 if (!varname) 03348 continue; 03349 03350 if (varname[0] == '_') { 03351 vartype = 1; 03352 if (varname[1] == '_') 03353 vartype = 2; 03354 } 03355 03356 switch (vartype) { 03357 case 1: 03358 newvar = ast_var_assign(&varname[1], ast_var_value(current)); 03359 if (newvar) { 03360 AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries); 03361 if (option_debug) 03362 ast_log(LOG_DEBUG, "Copying soft-transferable variable %s.\n", ast_var_name(newvar)); 03363 } 03364 break; 03365 case 2: 03366 newvar = ast_var_assign(ast_var_full_name(current), ast_var_value(current)); 03367 if (newvar) { 03368 AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries); 03369 if (option_debug) 03370 ast_log(LOG_DEBUG, "Copying hard-transferable variable %s.\n", ast_var_name(newvar)); 03371 } 03372 break; 03373 default: 03374 if (option_debug) 03375 ast_log(LOG_DEBUG, "Not copying variable %s.\n", ast_var_name(current)); 03376 break; 03377 } 03378 } 03379 }
| 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 3212 of file channel.c.
References AST_FORMAT_SLINEAR, ast_log(), ast_opt_transcode_via_slin, ast_set_read_format(), ast_set_write_format(), ast_translate_path_steps(), ast_translator_best_choice(), LOG_WARNING, and ast_channel::nativeformats.
Referenced by app_exec(), ast_channel_bridge(), check_compat(), park_exec(), try_calling(), and wait_for_answer().
03213 { 03214 int src; 03215 int dst; 03216 03217 /* Set up translation from the chan to the peer */ 03218 src = chan->nativeformats; 03219 dst = peer->nativeformats; 03220 if (ast_translator_best_choice(&dst, &src) < 0) { 03221 ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", chan->name, src, peer->name, dst); 03222 return -1; 03223 } 03224 03225 /* if the best path is not 'pass through', then 03226 transcoding is needed; if desired, force transcode path 03227 to use SLINEAR between channels, but only if there is 03228 no direct conversion available */ 03229 if ((src != dst) && ast_opt_transcode_via_slin && 03230 (ast_translate_path_steps(dst, src) != 1)) 03231 dst = AST_FORMAT_SLINEAR; 03232 if (ast_set_read_format(chan, dst) < 0) { 03233 ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", chan->name, dst); 03234 return -1; 03235 } 03236 if (ast_set_write_format(peer, dst) < 0) { 03237 ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", peer->name, dst); 03238 return -1; 03239 } 03240 03241 /* Set up translation from the peer to the chan */ 03242 src = peer->nativeformats; 03243 dst = chan->nativeformats; 03244 if (ast_translator_best_choice(&dst, &src) < 0) { 03245 ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", peer->name, src, chan->name, dst); 03246 return -1; 03247 } 03248 03249 /* if the best path is not 'pass through', then 03250 transcoding is needed; if desired, force transcode path 03251 to use SLINEAR between channels, but only if there is 03252 no direct conversion available */ 03253 if ((src != dst) && ast_opt_transcode_via_slin && 03254 (ast_translate_path_steps(dst, src) != 1)) 03255 dst = AST_FORMAT_SLINEAR; 03256 if (ast_set_read_format(peer, dst) < 0) { 03257 ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", peer->name, dst); 03258 return -1; 03259 } 03260 if (ast_set_write_format(chan, dst) < 0) { 03261 ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", chan->name, dst); 03262 return -1; 03263 } 03264 return 0; 03265 }
| 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 3267 of file channel.c.
References ast_channel::_bridge, ast_bridged_channel(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_log(), ast_null_frame, ast_queue_frame(), LOG_DEBUG, LOG_WARNING, ast_channel::masq, ast_channel::masqr, and option_debug.
Referenced by ast_async_goto(), ast_masq_park_call(), ast_pickup_call(), attempt_transfer(), builtin_atxfer(), check_availability(), check_bridge(), check_goto_on_transfer(), handle_invite_replaces(), iax_park(), misdn_transfer_bc(), pickup_do(), and sip_park().
03268 { 03269 int res = -1; 03270 struct ast_channel *final_orig = original, *final_clone = clone; 03271 03272 ast_channel_lock(original); 03273 while (ast_channel_trylock(clone)) { 03274 ast_channel_unlock(original); 03275 usleep(1); 03276 ast_channel_lock(original); 03277 } 03278 03279 /* each of these channels may be sitting behind a channel proxy (i.e. chan_agent) 03280 and if so, we don't really want to masquerade it, but its proxy */ 03281 if (original->_bridge && (original->_bridge != ast_bridged_channel(original)) && (original->_bridge->_bridge != original)) 03282 final_orig = original->_bridge; 03283 03284 if (clone->_bridge && (clone->_bridge != ast_bridged_channel(clone)) && (clone->_bridge->_bridge != clone)) 03285 final_clone = clone->_bridge; 03286 03287 if ((final_orig != original) || (final_clone != clone)) { 03288 ast_channel_lock(final_orig); 03289 while (ast_channel_trylock(final_clone)) { 03290 ast_channel_unlock(final_orig); 03291 usleep(1); 03292 ast_channel_lock(final_orig); 03293 } 03294 ast_channel_unlock(clone); 03295 ast_channel_unlock(original); 03296 original = final_orig; 03297 clone = final_clone; 03298 } 03299 03300 if (original == clone) { 03301 ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name); 03302 ast_channel_unlock(clone); 03303 ast_channel_unlock(original); 03304 return -1; 03305 } 03306 03307 if (option_debug) 03308 ast_log(LOG_DEBUG, "Planning to masquerade channel %s into the structure of %s\n", 03309 clone->name, original->name); 03310 if (original->masq) { 03311 ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", 03312 original->masq->name, original->name); 03313 } else if (clone->masqr) { 03314 ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n", 03315 clone->name, clone->masqr->name); 03316 } else { 03317 original->masq = clone; 03318 clone->masqr = original; 03319 ast_queue_frame(original, &ast_null_frame); 03320 ast_queue_frame(clone, &ast_null_frame); 03321 if (option_debug) 03322 ast_log(LOG_DEBUG, "Done planning to masquerade channel %s into the structure of %s\n", clone->name, original->name); 03323 res = 0; 03324 } 03325 03326 ast_channel_unlock(clone); 03327 ast_channel_unlock(original); 03328 03329 return res; 03330 }
| int ast_channel_register | ( | const struct ast_channel_tech * | tech | ) |
Register a channel technology (a new channel driver) Called by a channel module to register the kind of channels it supports.
| tech | Structure defining channel technology or "type" |
Definition at line 508 of file channel.c.
References ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_verbose(), LOG_DEBUG, LOG_WARNING, option_debug, option_verbose, chanlist::tech, ast_channel_tech::type, and VERBOSE_PREFIX_2.
Referenced by load_module(), and unload_module().
00509 { 00510 struct chanlist *chan; 00511 00512 AST_LIST_LOCK(&channels); 00513 00514 AST_LIST_TRAVERSE(&backends, chan, list) { 00515 if (!strcasecmp(tech->type, chan->tech->type)) { 00516 ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type); 00517 AST_LIST_UNLOCK(&channels); 00518 return -1; 00519 } 00520 } 00521 00522 if (!(chan = ast_calloc(1, sizeof(*chan)))) { 00523 AST_LIST_UNLOCK(&channels); 00524 return -1; 00525 } 00526 chan->tech = tech; 00527 AST_LIST_INSERT_HEAD(&backends, chan, list); 00528 00529 if (option_debug) 00530 ast_log(LOG_DEBUG, "Registered handler for '%s' (%s)\n", chan->tech->type, chan->tech->description); 00531 00532 if (option_verbose > 1) 00533 ast_verbose(VERBOSE_PREFIX_2 "Registered channel type '%s' (%s)\n", chan->tech->type, 00534 chan->tech->description); 00535 00536 AST_LIST_UNLOCK(&channels); 00537 return 0; 00538 }
| int ast_channel_sendhtml | ( | struct ast_channel * | channel, | |
| int | subclass, | |||
| const char * | data, | |||
| int | datalen | |||
| ) |
Send HTML or URL on link. Returns 0 on success or -1 on failure
Definition at line 3200 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().
03201 { 03202 if (chan->tech->send_html) 03203 return chan->tech->send_html(chan, subclass, data, datalen); 03204 return -1; 03205 }
| int ast_channel_sendurl | ( | struct ast_channel * | channel, | |
| const char * | url | |||
| ) |
Send URL on link. Returns 0 on success or -1 on failure
Definition at line 3207 of file channel.c.
References ast_channel_sendhtml(), and AST_HTML_URL.
Referenced by sendurl_exec(), and try_calling().
03208 { 03209 return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1); 03210 }
| int ast_channel_setoption | ( | struct ast_channel * | channel, | |
| int | option, | |||
| void * | data, | |||
| int | datalen, | |||
| int | block | |||
| ) |
Sets an option on a channel.
| channel | channel to set options on | |
| option | option to change | |
| data | data specific to option | |
| datalen | length of the data | |
| block | blocking or not Set an option on a channel (see frame.h), optionally blocking awaiting the reply Returns 0 on success and -1 on failure |
Definition at line 4190 of file channel.c.
References ast_log(), LOG_ERROR, ast_channel_tech::setoption, and ast_channel::tech.
Referenced by ast_bridge_call(), common_exec(), conf_run(), func_channel_write(), handle_tddmode(), play_record_review(), reset_volumes(), rpt(), set_listen_volume(), set_talk_volume(), set_volume(), try_calling(), vm_forwardoptions(), and zt_hangup().
04191 { 04192 int res; 04193 04194 if (chan->tech->setoption) { 04195 res = chan->tech->setoption(chan, option, data, datalen); 04196 if (res < 0) 04197 return res; 04198 } else { 04199 errno = ENOSYS; 04200 return -1; 04201 } 04202 if (block) { 04203 /* XXX Implement blocking -- just wait for our option frame reply, discarding 04204 intermediate packets. XXX */ 04205 ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n"); 04206 return -1; 04207 } 04208 return 0; 04209 }
| 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 from current time of when to hang up This function sets the absolute time out on a channel (when to hang up). |
Definition at line 478 of file channel.c.
References ast_null_frame, ast_queue_frame(), and ast_channel::whentohangup.
Referenced by action_timeout(), and timeout_write().
00479 { 00480 chan->whentohangup = offset ? time(NULL) + offset : 0; 00481 ast_queue_frame(chan, &ast_null_frame); 00482 return; 00483 }
| int ast_channel_spy_add | ( | struct ast_channel * | chan, | |
| struct ast_channel_spy * | spy | |||
| ) |
Adds a spy to a channel, to begin receiving copies of the channel's audio frames.
| chan | The channel to add the spy to. | |
| spy | A pointer to ast_channel_spy structure describing how the spy is to be used. |
Definition at line 1330 of file channel.c.
References ast_calloc, ast_clear_flag, ast_cond_init(), AST_FORMAT_SLINEAR, ast_getformatname(), AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_HEAD, AST_LIST_INSERT_TAIL, ast_log(), ast_set_flag, ast_test_flag, ast_channel_spy::chan, CHANSPY_FORMAT_AUDIO, CHANSPY_MIXAUDIO, CHANSPY_READ_VOLADJUST, CHANSPY_TRIGGER_MODE, CHANSPY_TRIGGER_NONE, CHANSPY_TRIGGER_READ, CHANSPY_TRIGGER_WRITE, CHANSPY_WRITE_VOLADJUST, ast_channel_spy_queue::format, LOG_DEBUG, LOG_WARNING, option_debug, ast_channel_spy::read_queue, ast_channel::spies, ast_channel_spy::trigger, ast_channel_spy::type, and ast_channel_spy::write_queue.
Referenced by start_spying(), and startmon().
01331 { 01332 /* Link the owner channel to the spy */ 01333 spy->chan = chan; 01334 01335 if (!ast_test_flag(spy, CHANSPY_FORMAT_AUDIO)) { 01336 ast_log(LOG_WARNING, "Could not add channel spy '%s' to channel '%s', only audio format spies are supported.\n", 01337 spy->type, chan->name); 01338 return -1; 01339 } 01340 01341 if (ast_test_flag(spy, CHANSPY_READ_VOLADJUST) && (spy->read_queue.format != AST_FORMAT_SLINEAR)) { 01342 ast_log(LOG_WARNING, "Cannot provide volume adjustment on '%s' format spies\n", 01343 ast_getformatname(spy->read_queue.format)); 01344 return -1; 01345 } 01346 01347 if (ast_test_flag(spy, CHANSPY_WRITE_VOLADJUST) && (spy->write_queue.format != AST_FORMAT_SLINEAR)) { 01348 ast_log(LOG_WARNING, "Cannot provide volume adjustment on '%s' format spies\n", 01349 ast_getformatname(spy->write_queue.format)); 01350 return -1; 01351 } 01352 01353 if (ast_test_flag(spy, CHANSPY_MIXAUDIO) && 01354 ((spy->read_queue.format != AST_FORMAT_SLINEAR) || 01355 (spy->write_queue.format != AST_FORMAT_SLINEAR))) { 01356 ast_log(LOG_WARNING, "Cannot provide audio mixing on '%s'-'%s' format spies\n", 01357 ast_getformatname(spy->read_queue.format), ast_getformatname(spy->write_queue.format)); 01358 return -1; 01359 } 01360 01361 if (!chan->spies) { 01362 if (!(chan->spies = ast_calloc(1, sizeof(*chan->spies)))) { 01363 return -1; 01364 } 01365 01366 AST_LIST_HEAD_INIT_NOLOCK(&chan->spies->list); 01367 AST_LIST_INSERT_HEAD(&chan->spies->list, spy, list); 01368 } else { 01369 AST_LIST_INSERT_TAIL(&chan->spies->list, spy, list); 01370 } 01371 01372 if (ast_test_flag(spy, CHANSPY_TRIGGER_MODE) != CHANSPY_TRIGGER_NONE) { 01373 ast_cond_init(&spy->trigger, NULL); 01374 ast_set_flag(spy, CHANSPY_TRIGGER_READ); 01375 ast_clear_flag(spy, CHANSPY_TRIGGER_WRITE); 01376 } 01377 01378 if (option_debug) 01379 ast_log(LOG_DEBUG, "Spy %s added to channel %s\n", 01380 spy->type, chan->name); 01381 01382 return 0; 01383 }
| void ast_channel_spy_free | ( | struct ast_channel_spy * | spy | ) |
Free a spy.
| spy | The spy to free |
Definition at line 1465 of file channel.c.
References ast_cond_destroy(), ast_frfree(), AST_LIST_REMOVE_HEAD, ast_mutex_destroy(), ast_test_flag, CHANSPY_DONE, CHANSPY_TRIGGER_MODE, CHANSPY_TRIGGER_NONE, f, ast_channel_spy::lock, ast_channel_spy::read_queue, ast_channel_spy::status, ast_channel_spy::trigger, and ast_channel_spy::write_queue.
Referenced by channel_spy(), and mixmonitor_thread().
01466 { 01467 struct ast_frame *f = NULL; 01468 01469 if (spy->status == CHANSPY_DONE) 01470 return; 01471 01472 /* Switch status to done in case we get called twice */ 01473 spy->status = CHANSPY_DONE; 01474 01475 /* Drop any frames in the queue */ 01476 while ((f = AST_LIST_REMOVE_HEAD(&spy->write_queue.list, frame_list))) 01477 ast_frfree(f); 01478 while ((f = AST_LIST_REMOVE_HEAD(&spy->read_queue.list, frame_list))) 01479 ast_frfree(f); 01480 01481 /* Destroy the condition if in use */ 01482 if (ast_test_flag(spy, CHANSPY_TRIGGER_MODE) != CHANSPY_TRIGGER_NONE) 01483 ast_cond_destroy(&spy->trigger); 01484 01485 /* Destroy our mutex since it is no longer in use */ 01486 ast_mutex_destroy(&spy->lock); 01487 01488 return; 01489 }
| struct ast_frame* ast_channel_spy_read_frame | ( | struct ast_channel_spy * | spy, | |
| unsigned int | samples | |||
| ) |
Read one (or more) frames of audio from a channel being spied upon.
| spy | The spy to operate on | |
| samples | The number of audio samples to read |
Note: This function performs no locking; you must hold the spy's lock before calling this function. You must not hold the channel's lock at the same time.
Definition at line 4506 of file channel.c.
References ast_clear_flag, ast_codec_get_len(), ast_frame_adjust_volume(), ast_frame_slinear_sum(), AST_FRAME_VOICE, ast_frdup(), ast_frfree(), AST_LIST_FIRST, AST_LIST_HEAD_SET_NOLOCK, AST_LIST_NEXT, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE, ast_test_flag, CHANSPY_MIXAUDIO, CHANSPY_READ_VOLADJUST, CHANSPY_TRIGGER_FLUSH, CHANSPY_WRITE_VOLADJUST, copy_data_from_queue(), ast_channel_spy_queue::format, ast_frame::frametype, ast_channel_spy::read_queue, ast_channel_spy::read_vol_adjustment, result, ast_channel_spy_queue::samples, ast_channel_spy::write_queue, and ast_channel_spy::write_vol_adjustment.
Referenced by mixmonitor_thread(), and spy_generate().
04507 { 04508 struct ast_frame *result; 04509 /* buffers are allocated to hold SLINEAR, which is the largest format */ 04510 short read_buf[samples]; 04511 short write_buf[samples]; 04512 struct ast_frame *read_frame; 04513 struct ast_frame *write_frame; 04514 int need_dup; 04515 struct ast_frame stack_read_frame = { .frametype = AST_FRAME_VOICE, 04516 .subclass = spy->read_queue.format, 04517 .data = read_buf, 04518 .samples = samples, 04519 .datalen = ast_codec_get_len(spy->read_queue.format, samples), 04520 }; 04521 struct ast_frame stack_write_frame = { .frametype = AST_FRAME_VOICE, 04522 .subclass = spy->write_queue.format, 04523 .data = write_buf, 04524 .samples = samples, 04525 .datalen = ast_codec_get_len(spy->write_queue.format, samples), 04526 }; 04527 04528 /* if a flush has been requested, dump everything in whichever queue is larger */ 04529 if (ast_test_flag(spy, CHANSPY_TRIGGER_FLUSH)) { 04530 if (spy->read_queue.samples > spy->write_queue.samples) { 04531 if (ast_test_flag(spy, CHANSPY_READ_VOLADJUST)) { 04532 AST_LIST_TRAVERSE(&spy->read_queue.list, result, frame_list) 04533 ast_frame_adjust_volume(result, spy->read_vol_adjustment); 04534 } 04535 result = AST_LIST_FIRST(&spy->read_queue.list); 04536 AST_LIST_HEAD_SET_NOLOCK(&spy->read_queue.list, NULL); 04537 spy->read_queue.samples = 0; 04538 } else { 04539 if (ast_test_flag(spy, CHANSPY_WRITE_VOLADJUST)) { 04540 AST_LIST_TRAVERSE(&spy->write_queue.list, result, frame_list) 04541 ast_frame_adjust_volume(result, spy->write_vol_adjustment); 04542 } 04543 result = AST_LIST_FIRST(&spy->write_queue.list); 04544 AST_LIST_HEAD_SET_NOLOCK(&spy->write_queue.list, NULL); 04545 spy->write_queue.samples = 0; 04546 } 04547 ast_clear_flag(spy, CHANSPY_TRIGGER_FLUSH); 04548 return result; 04549 } 04550 04551 if ((spy->read_queue.samples < samples) || (spy->write_queue.samples < samples)) 04552 return NULL; 04553 04554 /* short-circuit if both head frames have exactly what we want */ 04555 if ((AST_LIST_FIRST(&spy->read_queue.list)->samples == samples) && 04556 (AST_LIST_FIRST(&spy->write_queue.list)->samples == samples)) { 04557 read_frame = AST_LIST_REMOVE_HEAD(&spy->read_queue.list, frame_list); 04558 write_frame = AST_LIST_REMOVE_HEAD(&spy->write_queue.list, frame_list); 04559 04560 spy->read_queue.samples -= samples; 04561 spy->write_queue.samples -= samples; 04562 04563 need_dup = 0; 04564 } else { 04565 copy_data_from_queue(&spy->read_queue, read_buf, samples); 04566 copy_data_from_queue(&spy->write_queue, write_buf, samples); 04567 04568 read_frame = &stack_read_frame; 04569 write_frame = &stack_write_frame; 04570 need_dup = 1; 04571 } 04572 04573 if (ast_test_flag(spy, CHANSPY_READ_VOLADJUST)) 04574 ast_frame_adjust_volume(read_frame, spy->read_vol_adjustment); 04575 04576 if (ast_test_flag(spy, CHANSPY_WRITE_VOLADJUST)) 04577 ast_frame_adjust_volume(write_frame, spy->write_vol_adjustment); 04578 04579 if (ast_test_flag(spy, CHANSPY_MIXAUDIO)) { 04580 ast_frame_slinear_sum(read_frame, write_frame); 04581 04582 if (need_dup) 04583 result = ast_frdup(read_frame); 04584 else { 04585 result = read_frame; 04586 ast_frfree(write_frame); 04587 } 04588 } else { 04589 if (need_dup) { 04590 result = ast_frdup(read_frame); 04591 AST_LIST_NEXT(result, frame_list) = ast_frdup(write_frame); 04592 } else { 04593 result = read_frame; 04594 AST_LIST_NEXT(result, frame_list) = write_frame; 04595 } 04596 } 04597 04598 return result; 04599 }
| void ast_channel_spy_remove | ( | struct ast_channel * | chan, | |
| struct ast_channel_spy * | spy | |||
| ) |
Remove a spy from a channel.
| chan | The channel to remove the spy from | |
| spy | The spy to be removed |
Definition at line 1455 of file channel.c.
References AST_LIST_REMOVE, ast_channel::spies, spy_cleanup(), and spy_detach().
Referenced by channel_spy().
01456 { 01457 if (!chan->spies) 01458 return; 01459 01460 AST_LIST_REMOVE(&chan->spies->list, spy, list); 01461 spy_detach(spy, chan); 01462 spy_cleanup(chan); 01463 }
| void ast_channel_spy_stop_by_type | ( | struct ast_channel * | chan, | |
| const char * | type | |||
| ) |
Find all spies of a particular type on a channel and stop them.
| chan | The channel to operate on | |
| type | A character string identifying the type of spies to be stopped |
Definition at line 1423 of file channel.c.
References AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_mutex_lock(), ast_mutex_unlock(), ast_channel_spy::chan, CHANSPY_RUNNING, ast_channel_spy::lock, ast_channel::spies, spy_cleanup(), spy_detach(), ast_channel_spy::status, and ast_channel_spy::type.
Referenced by mixmonitor_cli(), and stop_mixmonitor_exec().
01424 { 01425 struct ast_channel_spy *spy = NULL; 01426 01427 if (!chan->spies) 01428 return; 01429 01430 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->spies->list, spy, list) { 01431 ast_mutex_lock(&spy->lock); 01432 if ((spy->type == type) && (spy->status == CHANSPY_RUNNING)) { 01433 ast_mutex_unlock(&spy->lock); 01434 AST_LIST_REMOVE_CURRENT(&chan->spies->list, list); 01435 spy_detach(spy, chan); 01436 } else 01437 ast_mutex_unlock(&spy->lock); 01438 } 01439 AST_LIST_TRAVERSE_SAFE_END 01440 spy_cleanup(chan); 01441 }
| void ast_channel_spy_trigger_wait | ( | struct ast_channel_spy * | spy | ) |
Efficiently wait until audio is available for a spy, or an exception occurs.
| spy | The spy to wait on |
Definition at line 1443 of file channel.c.
References ast_cond_timedwait(), ast_tvadd(), ast_channel_spy::lock, and ast_channel_spy::trigger.
Referenced by mixmonitor_thread().
01444 { 01445 struct timeval tv; 01446 struct timespec ts; 01447 01448 tv = ast_tvadd(ast_tvnow(), ast_samp2tv(50000, 1000)); 01449 ts.tv_sec = tv.tv_sec; 01450 ts.tv_nsec = tv.tv_usec * 1000; 01451 01452 ast_cond_timedwait(&spy->trigger, &spy->lock, &ts); 01453 }
| struct ast_silence_generator* ast_channel_start_silence_generator | ( | struct ast_channel * | chan | ) |
Starts a silence generator on the given channel.
| chan | The channel to generate silence on |
The pointer returned by this function must be preserved and passed to ast_channel_stop_silence_generator when you wish to stop the silence generation.
Definition at line 4638 of file channel.c.
References ast_activate_generator(), ast_calloc, AST_FORMAT_SLINEAR, ast_log(), ast_set_write_format(), free, LOG_DEBUG, LOG_ERROR, ast_silence_generator::old_write_format, silence_generator, and ast_channel::writeformat.
Referenced by __ast_play_and_record(), and channel_spy().
04639 { 04640 struct ast_silence_generator *state; 04641 04642 if (!(state = ast_calloc(1, sizeof(*state)))) { 04643 return NULL; 04644 } 04645 04646 state->old_write_format = chan->writeformat; 04647 04648 if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) { 04649 ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n"); 04650 free(state); 04651 return NULL; 04652 } 04653 04654 ast_activate_generator(chan, &silence_generator, state); 04655 04656 if (option_debug) 04657 ast_log(LOG_DEBUG, "Started silence generator on '%s'\n", chan->name); 04658 04659 return state; 04660 }
| void ast_channel_stop_silence_generator | ( | struct ast_channel * | chan, | |
| struct ast_silence_generator * | state | |||
| ) |
Stops a previously-started silence generator on the given channel.
| chan | The channel to operate on | |
| state | The ast_silence_generator pointer return by a previous call to ast_channel_start_silence_generator. |
Definition at line 4662 of file channel.c.
References ast_deactivate_generator(), ast_log(), ast_set_write_format(), free, LOG_DEBUG, LOG_ERROR, and ast_silence_generator::old_write_format.
Referenced by __ast_play_and_record(), and channel_spy().
04663 { 04664 if (!state) 04665 return; 04666 04667 ast_deactivate_generator(chan); 04668 04669 if (option_debug) 04670 ast_log(LOG_DEBUG, "Stopped silence generator on '%s'\n", chan->name); 04671 04672 if (ast_set_write_format(chan, state->old_write_format) < 0) 04673 ast_log(LOG_ERROR, "Could not return write format to its original state\n"); 04674 04675 free(state); 04676 }
| int ast_channel_supports_html | ( | struct ast_channel * | channel | ) |
Returns 0 if channel does not support HTML or non-zero if it does
Definition at line 3195 of file channel.c.
References ast_channel_tech::send_html, and ast_channel::tech.
Referenced by 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 983 of file channel.c.
References ast_clear_flag, and AST_FLAG_DEFER_DTMF.
Referenced by __adsi_transmit_messages(), find_cache(), and rpt_call().
00984 { 00985 if (chan) 00986 ast_clear_flag(chan, AST_FLAG_DEFER_DTMF); 00987 }
| void ast_channel_unregister | ( | const struct ast_channel_tech * | tech | ) |
Unregister a channel technology.
| tech | Structure defining channel technology or "type" that was previously registered |
Definition at line 540 of file channel.c.
References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log(), ast_verbose(), free, LOG_DEBUG, option_debug, option_verbose, chanlist::tech, ast_channel_tech::type, and VERBOSE_PREFIX_2.
Referenced by __unload_module(), and unload_module().
00541 { 00542 struct chanlist *chan; 00543 00544 if (option_debug) 00545 ast_log(LOG_DEBUG, "Unregistering channel type '%s'\n", tech->type); 00546 00547 AST_LIST_LOCK(&channels); 00548 00549 AST_LIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) { 00550 if (chan->tech == tech) { 00551 AST_LIST_REMOVE_CURRENT(&backends, list); 00552 free(chan); 00553 if (option_verbose > 1) 00554 ast_verbose(VERBOSE_PREFIX_2 "Unregistered channel type '%s'\n", tech->type); 00555 break; 00556 } 00557 } 00558 AST_LIST_TRAVERSE_SAFE_END 00559 00560 AST_LIST_UNLOCK(&channels); 00561 }
| struct ast_channel* ast_channel_walk_locked | ( | const struct ast_channel * | prev | ) |
Browse channels in use Browse the channels currently in use.
| prev | where you want to start in the channel list |
Definition at line 1073 of file channel.c.
References channel_find_locked().
Referenced by action_status(), ast_complete_channels(), ast_pickup_call(), complete_ch_helper(), conf_exec(), handle_chanlist(), handle_chanlist_deprecated(), handle_core_set_debug_channel(), handle_debugchan_deprecated(), handle_nodebugchan_deprecated(), moh_on_off(), next_channel(), pickup_by_exten(), pickup_by_mark(), and softhangup_exec().
01074 { 01075 return channel_find_locked(prev, NULL, 0, NULL, NULL); 01076 }
| int ast_channel_whisper_feed | ( | struct ast_channel * | chan, | |
| struct ast_frame * | f | |||
| ) |
Feed an audio frame into the whisper buffer on a channel.
| chan | The channel to whisper onto | |
| f | The frame to to whisper onto chan |
Definition at line 4876 of file channel.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_slinfactory_feed(), f, ast_channel_whisper_buffer::lock, ast_channel_whisper_buffer::sf, and ast_channel::whisper.
Referenced by channel_spy().
04877 { 04878 if (!chan->whisper) 04879 return -1; 04880 04881 ast_mutex_lock(&chan->whisper->lock); 04882 ast_slinfactory_feed(&chan->whisper->sf, f); 04883 ast_mutex_unlock(&chan->whisper->lock); 04884 04885 return 0; 04886 }
| int ast_channel_whisper_start | ( | struct ast_channel * | chan | ) |
Begin 'whispering' onto a channel.
| chan | The channel to whisper onto |
Definition at line 4861 of file channel.c.
References ast_calloc, AST_FLAG_WHISPER, ast_mutex_init(), ast_set_flag, ast_slinfactory_init(), ast_channel_whisper_buffer::lock, ast_channel_whisper_buffer::sf, and ast_channel::whisper.
Referenced by channel_spy().
04862 { 04863 if (chan->whisper) 04864 return -1; 04865 04866 if (!(chan->whisper = ast_calloc(1, sizeof(*chan->whisper)))) 04867 return -1; 04868 04869 ast_mutex_init(&chan->whisper->lock); 04870 ast_slinfactory_init(&chan->whisper->sf); 04871 ast_set_flag(chan, AST_FLAG_WHISPER); 04872 04873 return 0; 04874 }
| void ast_channel_whisper_stop | ( | struct ast_channel * | chan | ) |
Stop 'whispering' onto a channel.
| chan | The channel to whisper onto |
Definition at line 4888 of file channel.c.
References ast_clear_flag, AST_FLAG_WHISPER, AST_FORMAT_SLINEAR, ast_mutex_destroy(), ast_set_write_format(), ast_slinfactory_destroy(), ast_translator_free_path(), free, ast_channel_whisper_buffer::original_format, ast_channel_whisper_buffer::path, ast_channel::whisper, and ast_channel::writeformat.
Referenced by ast_channel_free(), and channel_spy().
04889 { 04890 if (!chan->whisper) 04891 return; 04892 04893 ast_clear_flag(chan, AST_FLAG_WHISPER); 04894 if (chan->whisper->path) 04895 ast_translator_free_path(chan->whisper->path); 04896 if (chan->whisper->original_format && chan->writeformat == AST_FORMAT_SLINEAR) 04897 ast_set_write_format(chan, chan->whisper->original_format); 04898 ast_slinfactory_destroy(&chan->whisper->sf); 04899 ast_mutex_destroy(&chan->whisper->lock); 04900 free(chan->whisper); 04901 chan->whisper = NULL; 04902 }
| void ast_channels_init | ( | void | ) |
Provided by channel.c
Definition at line 4439 of file channel.c.
References ast_cli_register_multiple(), and cli_channel.
Referenced by main().
04440 { 04441 ast_cli_register_multiple(cli_channel, sizeof(cli_channel) / sizeof(struct ast_cli_entry)); 04442 }
| struct ast_variable* ast_channeltype_list | ( | void | ) |
return an ast_variable list of channeltypes
Definition at line 180 of file channel.c.
References AST_LIST_TRAVERSE, ast_variable_new(), ast_channel_tech::description, chanlist::tech, ast_channel_tech::type, and var.
00181 { 00182 struct chanlist *cl; 00183 struct ast_variable *var=NULL, *prev = NULL; 00184 AST_LIST_TRAVERSE(&backends, cl, list) { 00185 if (prev) { 00186 if ((prev->next = ast_variable_new(cl->tech->type, cl->tech->description))) 00187 prev = prev->next; 00188 } else { 00189 var = ast_variable_new(cl->tech->type, cl->tech->description); 00190 prev = var; 00191 } 00192 } 00193 return var; 00194 }
| int ast_check_hangup | ( | struct ast_channel * | chan | ) |
Check to see if a channel is needing hang up.
| chan | channel on which to check for hang up This function determines if the channel is being requested to be hung up. |
Definition at line 402 of file channel.c.
References ast_channel::_softhangup, AST_SOFTHANGUP_TIMEOUT, ast_channel::tech_pvt, and ast_channel::whentohangup.
Referenced by __ast_read(), action_redirect(), app_exec(), ast_answer(), ast_call(), ast_channel_bridge(), ast_check_hangup_locked(), ast_feature_request_and_dial(), ast_indicate_data(), ast_readstring_full(), ast_recvtext(), ast_sendtext(), ast_transfer(), ast_udptl_bridge(), ast_waitfordigit_full(), ast_write(), bridge_native_loop(), bridge_p2p_loop(), builtin_atxfer(), channel_spy(), common_exec(), handle_sendimage(), rpt(), rpt_exec(), zt_sendtext(), and zt_setoption().
00403 { 00404 if (chan->_softhangup) /* yes if soft hangup flag set */ 00405 return 1; 00406 if (!chan->tech_pvt) /* yes if no technology private data */ 00407 return 1; 00408 if (!chan->whentohangup) /* no if no hangup scheduled */ 00409 return 0; 00410 if (chan->whentohangup > time(NULL)) /* no if hangup time has not come yet. */ 00411 return 0; 00412 chan->_softhangup |= AST_SOFTHANGUP_TIMEOUT; /* record event */ 00413 return 1; 00414 }
| static int ast_check_hangup_locked | ( | struct ast_channel * | chan | ) | [static] |
Definition at line 416 of file channel.c.
References ast_channel_lock, ast_channel_unlock, and ast_check_hangup().
Referenced by ast_channel_bridge().
00417 { 00418 int res; 00419 ast_channel_lock(chan); 00420 res = ast_check_hangup(chan); 00421 ast_channel_unlock(chan); 00422 return res; 00423 }
| void ast_deactivate_generator | ( | struct ast_channel * | chan | ) |
Deactive an active generator
Definition at line 1779 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_clear_flag, AST_FLAG_WRITE_INT, AST_GENERATOR_FD, ast_settimeout(), ast_channel::fds, 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_tonepair_stop(), ast_write(), channel_spy(), generator_force(), local_ast_moh_stop(), milliwatt_exec(), moh_on_off(), and wait_for_answer().
01780 { 01781 ast_channel_lock(chan); 01782 if (chan->generatordata) { 01783 if (chan->generator && chan->generator->release) 01784 chan->generator->release(chan, chan->generatordata); 01785 chan->generatordata = NULL; 01786 chan->generator = NULL; 01787 chan->fds[AST_GENERATOR_FD] = -1; 01788 ast_clear_flag(chan, AST_FLAG_WRITE_INT); 01789 ast_settimeout(chan, 0, NULL, NULL); 01790 } 01791 ast_channel_unlock(chan); 01792 }
| int ast_do_masquerade | ( | struct ast_channel * | original | ) |
Start masquerading a channel XXX This is a seriously wacked 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 3403 of file channel.c.
References ast_channel::_state, ast_channel::alertpipe, ast_channel_lock, AST_LIST_FIRST, AST_LIST_HEAD_SET_NOLOCK, AST_LIST_TRAVERSE, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_string_field_set, ast_channel::cdr, ast_channel_spy::chan, EVENT_FLAG_CALL, free_translation(), ast_channel::lock, ast_channel_spy::lock, LOG_DEBUG, manager_event(), ast_channel::masq, ast_channel::masqr, name, option_debug, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::spies, t, ast_channel::tech, ast_channel::tech_pvt, and ast_channel::writeformat.
Referenced by __ast_read(), ast_async_goto(), ast_hangup(), ast_waitfor_nandfds(), ast_write(), iax_park(), sip_park(), and sip_park_thread().
03404 { 03405 int x,i; 03406 int res=0; 03407 int origstate; 03408 struct ast_frame *cur; 03409 const struct ast_channel_tech *t; 03410 void *t_pvt; 03411 struct ast_callerid tmpcid; 03412 struct ast_channel *clone = original->masq; 03413 struct ast_channel_spy_list *spy_list = NULL; 03414 struct ast_channel_spy *spy = NULL; 03415 struct ast_cdr *cdr; 03416 int rformat = original->readformat; 03417 int wformat = original->writeformat; 03418 char newn[100]; 03419 char orig[100]; 03420 char masqn[100]; 03421 char zombn[100]; 03422 03423 if (option_debug > 3) 03424 ast_log(LOG_DEBUG, "Actually Masquerading %s(%d) into the structure of %s(%d)\n", 03425 clone->name, clone->_state, original->name, original->_state); 03426 03427 /* XXX This is a seriously wacked out operation. We're essentially putting the guts of 03428 the clone channel into the original channel. Start by killing off the original 03429 channel's backend. I'm not sure we're going to keep this function, because 03430 while the features are nice, the cost is very high in terms of pure nastiness. XXX */ 03431 03432 /* We need the clone's lock, too */ 03433 ast_channel_lock(clone); 03434 03435 if (option_debug > 1) 03436 ast_log(LOG_DEBUG, "Got clone lock for masquerade on '%s' at %p\n", clone->name, &clone->lock); 03437 03438 /* Having remembered the original read/write formats, we turn off any translation on either 03439 one */ 03440 free_translation(clone); 03441 free_translation(original); 03442 03443 03444 /* Unlink the masquerade */ 03445 original->masq = NULL; 03446 clone->masqr = NULL; 03447 03448 /* Save the original name */ 03449 ast_copy_string(orig, original->name, sizeof(orig)); 03450 /* Save the new name */ 03451 ast_copy_string(newn, clone->name, sizeof(newn)); 03452 /* Create the masq name */ 03453 snprintf(masqn, sizeof(masqn), "%s<MASQ>", newn); 03454 03455 /* Copy the name from the clone channel */ 03456 ast_string_field_set(original, name, newn); 03457 03458 /* Mangle the name of the clone channel */ 03459 ast_string_field_set(clone, name, masqn); 03460 03461 /* Notify any managers of the change, first the masq then the other */ 03462 manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", newn, masqn, clone->uniqueid); 03463 manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", orig, newn, original->uniqueid); 03464 03465 /* Swap the technologies */ 03466 t = original->tech; 03467 original->tech = clone->tech; 03468 clone->tech = t; 03469 03470 /* Swap the cdrs */ 03471 cdr = original->cdr; 03472 original->cdr = clone->cdr; 03473 clone->cdr = cdr; 03474 03475 t_pvt = original->tech_pvt; 03476 original->tech_pvt = clone->tech_pvt; 03477 clone->tech_pvt = t_pvt; 03478 03479 /* Swap the readq's */ 03480 cur = AST_LIST_FIRST(&original->readq); 03481 AST_LIST_HEAD_SET_NOLOCK(&original->readq, AST_LIST_FIRST(&clone->readq)); 03482 AST_LIST_HEAD_SET_NOLOCK(&clone->readq, cur); 03483 03484 /* Swap the alertpipes */ 03485 for (i = 0; i < 2; i++) { 03486 x = original->alertpipe[i]; 03487 original->alertpipe[i] = clone->alertpipe[i]; 03488 clone->alertpipe[i] = x; 03489 } 03490 03491 /* Swap the raw formats */ 03492 x = original->rawreadformat; 03493 original->rawreadformat = clone->rawreadformat; 03494 clone->rawreadformat = x; 03495 x = original->rawwriteformat; 03496 original->rawwriteformat = clone->rawwriteformat; 03497 clone->rawwriteformat = x; 03498 03499 /* Swap the spies */ 03500 spy_list = original->spies; 03501 original->spies = clone->spies; 03502 clone->spies = spy_list; 03503 03504 /* Update channel on respective spy lists if present */ 03505 if (original->spies) { 03506 AST_LIST_TRAVERSE(&original->spies->list, spy, list) { 03507 ast_mutex_lock(&spy->lock); 03508 spy->chan = original; 03509 ast_mutex_unlock(&spy->lock); 03510 } 03511 } 03512 if (clone->spies) { 03513 AST_LIST_TRAVERSE(&clone->spies->list, spy, list) { 03514 ast_mutex_lock(&spy->lock); 03515 spy->chan = clone; 03516 ast_mutex_unlock(&spy->lock); 03517 } 03518 } 03519 03520 /* Save any pending frames on both sides. Start by counting 03521 * how many we're going to need... */ 03522 x = 0; 03523 if (original->alertpipe[1] > -1) { 03524 AST_LIST_TRAVERSE(&clone->readq, cur, frame_list) 03525 x++; 03526 } 03527 03528 /* If we had any, prepend them to the ones already in the queue, and 03529 * load up the alertpipe */ 03530 if (AST_LIST_FIRST(&clone->readq)) { 03531 AST_LIST_INSERT_TAIL(&clone->readq, AST_LIST_FIRST(&original->readq), frame_list); 03532 AST_LIST_HEAD_SET_NOLOCK(&original->readq, AST_LIST_FIRST(&clone->readq)); 03533 AST_LIST_HEAD_SET_NOLOCK(&clone->readq, NULL); 03534 for (i = 0; i < x; i++) 03535 write(original->alertpipe[1], &x, sizeof(x)); 03536 } 03537 03538 clone->_softhangup = AST_SOFTHANGUP_DEV; 03539 03540 03541 /* And of course, so does our current state. Note we need not 03542 call ast_setstate since the event manager doesn't really consider 03543 these separate. We do this early so that the clone has the proper 03544 state of the original channel. */ 03545 origstate = original->_state; 03546 original->_state = clone->_state; 03547 clone->_state = origstate; 03548 03549 if (clone->tech->fixup){ 03550 res = clone->tech->fixup(original, clone); 03551 if (res) 03552 ast_log(LOG_WARNING, "Fixup failed on channel %s, strange things may happen.\n", clone->name); 03553 } 03554 03555 /* Start by disconnecting the original's physical side */ 03556 if (clone->tech->hangup) 03557 res = clone->tech->hangup(clone); 03558 if (res) { 03559 ast_log(LOG_WARNING, "Hangup failed! Strange things may happen!\n"); 03560 ast_channel_unlock(clone); 03561 return -1; 03562 } 03563 03564 snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig); 03565 /* Mangle the name of the clone channel */ 03566 ast_string_field_set(clone, name, zombn); 03567 manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", masqn, zombn, clone->uniqueid); 03568 03569 /* Update the type. */ 03570 t_pvt = original->monitor; 03571 original->monitor = clone->monitor; 03572 clone->monitor = t_pvt; 03573 03574 /* Keep the same language. */ 03575 ast_string_field_set(original, language, clone->language); 03576 /* Copy the FD's other than the generator fd */ 03577 for (x = 0; x < AST_MAX_FDS; x++) { 03578 if (x != AST_GENERATOR_FD) 03579 original->fds[x] = clone->fds[x]; 03580 } 03581 03582 ast_app_group_discard(original); 03583 03584 /* move any whisperer over */ 03585 ast_channel_whisper_stop(original); 03586 if (ast_test_flag(clone, AST_FLAG_WHISPER)) { 03587 original->whisper = clone->whisper; 03588 ast_set_flag(original, AST_FLAG_WHISPER); 03589 clone->whisper = NULL; 03590 ast_clear_flag(clone, AST_FLAG_WHISPER); 03591 } 03592 03593 /* Move data stores over */ 03594 if (AST_LIST_FIRST(&clone->datastores)) 03595 AST_LIST_INSERT_TAIL(&original->datastores, AST_LIST_FIRST(&clone->datastores), entry); 03596 AST_LIST_HEAD_INIT_NOLOCK(&clone->datastores); 03597 03598 clone_variables(original, clone); 03599 AST_LIST_HEAD_INIT_NOLOCK(&clone->varshead); 03600 /* Presense of ADSI capable CPE follows clone */ 03601 original->adsicpe = clone->adsicpe; 03602 /* Bridge remains the same */ 03603 /* CDR fields remain the same */ 03604 /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */ 03605 /* Application and data remain the same */ 03606 /* Clone exception becomes real one, as with fdno */ 03607 ast_copy_flags(original, clone, AST_FLAG_EXCEPTION); 03608 original->fdno = clone->fdno; 03609 /* Schedule context remains the same */ 03610 /* Stream stuff stays the same */ 03611 /* Keep the original state. The fixup code will need to work with it most likely */ 03612 03613 /* Just swap the whole structures, nevermind the allocations, they'll work themselves 03614 out. */ 03615 tmpcid = original->cid; 03616 original->cid = clone->cid; 03617 clone->cid = tmpcid; 03618 03619 /* Restore original timing file descriptor */ 03620 original->fds[AST_TIMING_FD] = original->timingfd; 03621 03622 /* Our native formats are different now */ 03623 original->nativeformats = clone->nativeformats; 03624 03625 /* Context, extension, priority, app data, jump table, remain the same */ 03626 /* pvt switches. pbx stays the same, as does next */ 03627 03628 /* Set the write format */ 03629 ast_set_write_format(original, wformat); 03630 03631 /* Set the read format */ 03632 ast_set_read_format(original, rformat); 03633 03634 /* Copy the music class */ 03635 ast_string_field_set(original, musicclass, clone->musicclass); 03636 03637 if (option_debug) 03638 ast_log(LOG_DEBUG, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat); 03639 03640 /* Okay. Last thing is to let the channel driver know about all this mess, so he 03641 can fix up everything as best as possible */ 03642 if (original->tech->fixup) { 03643 res = original->tech->fixup(clone, original); 03644 if (res) { 03645 ast_log(LOG_WARNING, "Channel for type '%s' could not fixup channel %s\n", 03646 original->tech->type, original->name); 03647 ast_channel_unlock(clone); 03648 return -1; 03649 } 03650 } else 03651 ast_log(LOG_WARNING, "Channel type '%s' does not have a fixup routine (for %s)! Bad things may happen.\n", 03652 original->tech->type, original->name); 03653 03654 /* Now, at this point, the "clone" channel is totally F'd up. We mark it as 03655 a zombie so nothing tries to touch it. If it's already been marked as a 03656 zombie, then free it now (since it already is considered invalid). */ 03657 if (ast_test_flag(clone, AST_FLAG_ZOMBIE)) { 03658 if (option_debug) 03659 ast_log(LOG_DEBUG, "Destroying channel clone '%s'\n", clone->name); 03660 ast_channel_unlock(clone); 03661 manager_event(EVENT_FLAG_CALL, "Hangup", 03662 "Channel: %s\r\n" 03663 "Uniqueid: %s\r\n" 03664 "Cause: %d\r\n" 03665 "Cause-txt: %s\r\n", 03666 clone->name, 03667 clone->uniqueid, 03668 clone->hangupcause, 03669 ast_cause2str(clone->hangupcause) 03670 ); 03671 ast_channel_free(clone); 03672 } else { 03673 if (option_debug) 03674 ast_log(LOG_DEBUG, "Released clone lock on '%s'\n", clone->name); 03675 ast_set_flag(clone, AST_FLAG_ZOMBIE); 03676 ast_queue_frame(clone, &ast_null_frame); 03677 ast_channel_unlock(clone); 03678 } 03679 03680 /* Signal any blocker */ 03681 if (ast_test_flag(original, AST_FLAG_BLOCKING)) 03682 pthread_kill(original->blocker, SIGURG); 03683 if (option_debug) 03684 ast_log(LOG_DEBUG, "Done Masquerading %s (%d)\n", original->name, original->_state); 03685 return 0; 03686 }
| 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 3791 of file channel.c.
References AST_BRIDGE_COMPLETE, AST_BRIDGE_DTMF_CHANNEL_0, AST_BRIDGE_DTMF_CHANNEL_1, AST_BRIDGE_RETRY, ast_jb_do_usecheck(), config, f, ast_channel::nativeformats, and ast_channel::tech_pvt.
Referenced by ast_channel_bridge().
03794 { 03795 /* Copy voice back and forth between the two channels. */ 03796 struct ast_channel *cs[3]; 03797 struct ast_frame *f; 03798 enum ast_bridge_result res = AST_BRIDGE_COMPLETE; 03799 int o0nativeformats; 03800 int o1nativeformats; 03801 int watch_c0_dtmf; 03802 int watch_c1_dtmf; 03803 void *pvt0, *pvt1; 03804 /* Indicates whether a frame was queued into a jitterbuffer */ 03805 int frame_put_in_jb = 0; 03806 int jb_in_use; 03807 int to; 03808 03809 cs[0] = c0; 03810 cs[1] = c1; 03811 pvt0 = c0->tech_pvt; 03812 pvt1 = c1->tech_pvt; 03813 o0nativeformats = c0->nativeformats; 03814 o1nativeformats = c1->nativeformats; 03815 watch_c0_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_0; 03816 watch_c1_dtmf = config->flags & AST_BRIDGE_DTMF_CHANNEL_1; 03817 03818 /* Check the need of a jitterbuffer for each channel */ 03819 jb_in_use = ast_jb_do_usecheck(c0, c1); 03820 03821 for (;;) { 03822 struct ast_channel *who, *other; 03823 03824 if ((c0->tech_pvt != pvt0) || (c1->tech_pvt != pvt1) || 03825 (o0nativeformats != c0->nativeformats) || 03826 (o1nativeformats != c1->nativeformats)) { 03827 /* Check for Masquerade, codec changes, etc */ 03828 res = AST_BRIDGE_RETRY; 03829 break; 03830 } 03831 if (bridge_end.tv_sec) { 03832 to = ast_tvdiff_ms(bridge_end, ast_tvnow()); 03833 if (to <= 0) { 03834 if (config->timelimit) 03835 res = AST_BRIDGE_RETRY; 03836 else 03837 res = AST_BRIDGE_COMPLETE; 03838 break; 03839 } 03840 } else 03841 to = -1; 03842 /* Calculate the appropriate max sleep interval - in general, this is the time, 03843 left to the closest jb delivery moment */ 03844 if (jb_in_use) 03845 to = ast_jb_get_when_to_wakeup(c0, c1, to); 03846 who = ast_waitfor_n(cs, 2, &to); 03847 if (!who) { 03848 /* No frame received within the specified timeout - check if we have to deliver now */ 03849 if (jb_in_use) 03850 ast_jb_get_and_deliver(c0, c1); 03851 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) { 03852 if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 03853 c0->_softhangup = 0; 03854 if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) 03855 c1->_softhangup = 0; 03856 c0->_bridge = c1; 03857 c1->_bridge = c0; 03858 } 03859 continue; 03860 } 03861 f = ast_read(who); 03862 if (!f) { 03863 *fo = NULL; 03864 *rc = who; 03865 if (option_debug) 03866 ast_log(LOG_DEBUG, "Didn't get a frame from channel: %s\n",who->name); 03867 break; 03868 } 03869 03870 other = (who == c0) ? c1 : c0; /* the 'other' channel */ 03871 /* Try add the frame info the who's bridged channel jitterbuff */ 03872 if (jb_in_use) 03873 frame_put_in_jb = !ast_jb_put(other, f); 03874 03875 if ((f->frametype == AST_FRAME_CONTROL) && !(config->flags & AST_BRIDGE_IGNORE_SIGS)) { 03876 int bridge_exit = 0; 03877 03878 switch (f->subclass) { 03879 case AST_CONTROL_HOLD: 03880 case AST_CONTROL_UNHOLD: 03881 case AST_CONTROL_VIDUPDATE: 03882 ast_indicate_data(other, f->subclass, f->data, f->datalen); 03883 break; 03884 default: 03885 *fo = f; 03886 *rc = who; 03887 bridge_exit = 1; 03888 if (option_debug) 03889 ast_log(LOG_DEBUG, "Got a FRAME_CONTROL (%d) frame on channel %s\n", f->subclass, who->name); 03890 break; 03891 } 03892 if (bridge_exit) 03893 break; 03894 } 03895 if ((f->frametype == AST_FRAME_VOICE) || 03896 (f->frametype == AST_FRAME_DTMF_BEGIN) || 03897 (f->frametype == AST_FRAME_DTMF) || 03898 (f->frametype == AST_FRAME_VIDEO) || 03899 (f->frametype == AST_FRAME_IMAGE) || 03900 (f->frametype == AST_FRAME_HTML) || 03901 (f->frametype == AST_FRAME_MODEM) || 03902 (f->frametype == AST_FRAME_TEXT)) { 03903 /* monitored dtmf causes exit from bridge */ 03904 int monitored_source = (who == c0) ? watch_c0_dtmf : watch_c1_dtmf; 03905 03906 if (monitored_source && 03907 (f->frametype == AST_FRAME_DTMF_END || 03908 f->frametype == AST_FRAME_DTMF_BEGIN)) { 03909 *fo = f; 03910 *rc = who; 03911 if (option_debug) 03912 ast_log(LOG_DEBUG, "Got DTMF %s on channel (%s)\n", 03913 f->frametype == AST_FRAME_DTMF_END ? "end" : "begin", 03914 who->name); 03915 break; 03916 } 03917 /* Write immediately frames, not passed through jb */ 03918 if (!frame_put_in_jb) 03919 ast_write(other, f); 03920 03921 /* Check if we have to deliver now */ 03922 if (jb_in_use) 03923 ast_jb_get_and_deliver(c0, c1); 03924 } 03925 /* XXX do we want to pass on also frames not matched above ? */ 03926 ast_frfree(f); 03927 03928 /* Swap who gets priority */ 03929 cs[2] = cs[0]; 03930 cs[0] = cs[1]; 03931 cs[1] = cs[2]; 03932 } 03933 return res; 03934 }
| struct ast_channel* ast_get_channel_by_exten_locked | ( | const char * | exten, | |
| const char * | context | |||
| ) |
Get channel by exten (and optionally context) and lock it.
Definition at line 1098 of file channel.c.
References channel_find_locked().
01099 { 01100 return channel_find_locked(NULL, NULL, 0, context, exten); 01101 }
| struct ast_channel* ast_get_channel_by_name_locked | ( | const char * | name | ) |
Get channel by name (locks channel).
Definition at line 1079 of file channel.c.
References channel_find_locked().
Referenced by action_getvar(), action_hangup(), action_redirect(), action_setcdruserfield(), action_setvar(), action_status(), action_timeout(), ast_async_goto_by_name(), asyncgoto_exec(), change_monitor_action(), do_pause_or_unpause(), get_zap_channel_locked(), handle_channelstatus(), handle_core_set_debug_channel(), handle_debugchan_deprecated(), handle_getvariablefull(), handle_hangup(), handle_nodebugchan_deprecated(), handle_showchan(), handle_showchan_deprecated(), handle_softhangup(), manager_park(), manager_play_dtmf(), pbx_builtin_importvar(), start_monitor_action(), and stop_monitor_action().
01080 { 01081 return channel_find_locked(NULL, name, 0, NULL, NULL); 01082 }
| struct ast_channel* ast_get_channel_by_name_prefix_locked | ( | const char * | name, | |
| const int | namelen | |||
| ) |
Get channel by name prefix (locks channel).
Definition at line 1085 of file channel.c.
References channel_find_locked().
Referenced by ast_parse_device_state(), common_exec(), and mixmonitor_cli().
01086 { 01087 return channel_find_locked(NULL, name, namelen, NULL, NULL); 01088 }
| struct ast_channel_tech* ast_get_channel_tech | ( | const char * | name | ) |
Get a channel technology structure by name.
| name | name of technology to find |
Definition at line 563 of file channel.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), LOG_WARNING, chanlist::tech, and ast_channel_tech::type.
Referenced by ast_device_state().
00564 { 00565 struct chanlist *chanls; 00566 const struct ast_channel_tech *ret = NULL; 00567 00568 if (AST_LIST_LOCK(&channels)) { 00569 ast_log(LOG_WARNING, "Unable to lock channel tech list\n"); 00570 return NULL; 00571 } 00572 00573 AST_LIST_TRAVERSE(&backends, chanls, list) { 00574 if (!strcasecmp(name, chanls->tech->type)) { 00575 ret = chanls->tech; 00576 break; 00577 } 00578 } 00579 00580 AST_LIST_UNLOCK(&channels); 00581 00582 return ret; 00583 }
| ast_group_t ast_get_group | ( | const char * | s | ) |
Definition at line 4363 of file channel.c.
References ast_log(), ast_strdupa, group, LOG_ERROR, LOG_WARNING, and strsep().
Referenced by _parse(), build_device(), build_gateway(), build_peer(), func_channel_write(), process_zap(), and read_agent_config().
04364 { 04365 char *piece; 04366 char *c; 04367 int start=0, finish=0, x; 04368 ast_group_t group = 0; 04369 04370 c = ast_strdupa(s); 04371 04372 while ((piece = strsep(&c, ","))) { 04373 if (sscanf(piece, "%d-%d", &start, &finish) == 2) { 04374 /* Range */ 04375 } else if (sscanf(piece, "%d", &start)) { 04376 /* Just one */ 04377 finish = start; 04378 } else { 04379 ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece); 04380 continue; 04381 } 04382 for (x = start; x <= finish; x++) { 04383 if ((x > 63) || (x < 0)) { 04384 ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x); 04385 } else 04386 group |= ((ast_group_t) 1 << x); 04387 } 04388 } 04389 return group; 04390 }
| int ast_hangup | ( | struct ast_channel * | chan | ) |
Hang up a channel.
| chan | channel to hang up |
Definition at line 1664 of file channel.c.
References ast_cause2str(), ast_cdr_detach(), ast_cdr_end(), ast_channel_free(), ast_channel_lock, ast_channel_unlock, ast_closestream(), ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_ZOMBIE, ast_log(), ast_set_flag, ast_test_flag, ast_channel::blocker, ast_channel::blockproc, ast_channel::cdr, CRASH, detach_spies(), EVENT_FLAG_CALL, free_translation(), ast_channel::generator, ast_channel::generatordata, ast_channel_tech::hangup, ast_channel::hangupcause, LOG_DEBUG, LOG_WARNING, manager_event(), ast_channel::masq, ast_channel::masqr, option_debug, ast_generator::release, ast_channel::sched, sched_context_destroy(), ast_channel::stream, ast_channel::tech, and ast_channel::vstream.
Referenced by __ast_request_and_dial(), __oh323_new(), agent_hangup(), agent_read(), alsa_new(), app_exec(), ast_async_goto(), ast_bridge_call_thread(), ast_dial_destroy(), ast_dial_hangup(), ast_feature_request_and_dial(), ast_iax2_new(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_pbx_run_app(), async_wait(), begin_dial(), build_conf(), builtin_atxfer(), chanavail_exec(), check_compat(), check_goto_on_transfer(), clear_caller(), conf_free(), conf_run(), do_hang(), do_parking_thread(), features_hangup(), findmeexec(), function_ilink(), gtalk_new(), 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(), hangup_chan(), hangupcalls(), hanguptree(), iax2_request(), iax_park(), iax_park_thread(), local_attended_transfer(), local_hangup(), mgcp_new(), mgcp_ss(), monitor_dial(), nbs_new(), oss_new(), park_exec(), parkandannounce_exec(), phone_new(), rpt(), rpt_call(), rpt_exec(), rpt_tele_thread(), sip_new(), sip_park(), sip_park_thread(), skinny_new(), skinny_ss(), ss_thread(), try_calling(), wait_for_answer(), wait_for_winner(), zt_handle_event(), and zt_new().
01665 { 01666 int res = 0; 01667 01668 /* Don't actually hang up a channel that will masquerade as someone else, or 01669 if someone is going to masquerade as us */ 01670 ast_channel_lock(chan); 01671 01672 detach_spies(chan); /* get rid of spies */ 01673 01674 if (chan->masq) { 01675 if (ast_do_masquerade(chan)) 01676 ast_log(LOG_WARNING, "Failed to perform masquerade\n"); 01677 } 01678 01679 if (chan->masq) { 01680 ast_log(LOG_WARNING, "%s getting hung up, but someone is trying to masq into us?!?\n", chan->name); 01681 ast_channel_unlock(chan); 01682 return 0; 01683 } 01684 /* If this channel is one which will be masqueraded into something, 01685 mark it as a zombie already, so we know to free it later */ 01686 if (chan->masqr) { 01687 ast_set_flag(chan, AST_FLAG_ZOMBIE); 01688 ast_channel_unlock(chan); 01689 return 0; 01690 } 01691 free_translation(chan); 01692 /* Close audio stream */ 01693 if (chan->stream) { 01694 ast_closestream(chan->stream); 01695 chan->stream = NULL; 01696 } 01697 /* Close video stream */ 01698 if (chan->vstream) { 01699 ast_closestream(chan->vstream); 01700 chan->vstream = NULL; 01701 } 01702 if (chan->sched) { 01703 sched_context_destroy(chan->sched); 01704 chan->sched = NULL; 01705 } 01706 01707 if (chan->generatordata) /* Clear any tone stuff remaining */ 01708 chan->generator->release(chan, chan->generatordata); 01709 chan->generatordata = NULL; 01710 chan->generator = NULL; 01711 if (chan->cdr) { /* End the CDR if it hasn't already */ 01712 ast_cdr_end(chan->cdr); 01713 ast_cdr_detach(chan->cdr); /* Post and Free the CDR */ 01714 chan->cdr = NULL; 01715 } 01716 if (ast_test_flag(chan, AST_FLAG_BLOCKING)) { 01717 ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd " 01718 "is blocked by thread %ld in procedure %s! Expect a failure\n", 01719 (long)pthread_self(), chan->name, (long)chan->blocker, chan->blockproc); 01720 CRASH; 01721 } 01722 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE)) { 01723 if (option_debug) 01724 ast_log(LOG_DEBUG, "Hanging up channel '%s'\n", chan->name); 01725 if (chan->tech->hangup) 01726 res = chan->tech->hangup(chan); 01727 } else { 01728 if (option_debug) 01729 ast_log(LOG_DEBUG, "Hanging up zombie '%s'\n", chan->name); 01730 } 01731 01732 ast_channel_unlock(chan); 01733 manager_event(EVENT_FLAG_CALL, "Hangup", 01734 "Channel: %s\r\n" 01735 "Uniqueid: %s\r\n" 01736 "Cause: %d\r\n" 01737 "Cause-txt: %s\r\n", 01738 chan->name, 01739 chan->uniqueid, 01740 chan->hangupcause, 01741 ast_cause2str(chan->hangupcause) 01742 ); 01743 ast_channel_free(chan); 01744 return res; 01745 }
| 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 2460 of file channel.c.
References ast_indicate_data().
Referenced by __ast_play_and_record(), agent_new(), ast_bridge_call(), ast_dtmf_stream(), ast_feature_request_and_dial(), attempt_transfer(), builtin_atxfer(), builtin_blindtransfer(), conf_run(), disa_exec(), do_parking_thread(), features_indicate(), finishup(), function_remote(), handle_frame(), handle_recordfile(), handle_remote_data(), handle_remote_phone_dtmf(), mgcp_ss(), monitor_dial(), park_exec(), pbx_builtin_busy(), pbx_builtin_congestion(), pbx_builtin_progress(), pbx_builtin_ringing(), pbx_builtin_waitexten(), queue_exec(), rmt_telem_finish(), rmt_telem_start(), rpt(), rpt_exec(), send_waveform_to_channel(), skinny_ss(), sla_handle_hold_event(), sla_station_exec(), sla_trunk_exec(), and wait_for_answer().
02461 { 02462 return ast_indicate_data(chan, condition, NULL, 0); 02463 }
| 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 2465 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_check_hangup(), AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HOLD, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, AST_FLAG_ZOMBIE, ast_get_indication_tone(), ast_log(), ast_playtones_start(), ast_playtones_stop(), ast_test_flag, tone_zone_sound::data, ast_channel_tech::indicate, LOG_DEBUG, LOG_WARNING, option_debug, ast_channel::tech, and ast_channel::zone.
Referenced by __login_exec(), agent_hangup(), ast_indicate(), ast_park_call(), bridge_native_loop(), bridge_p2p_loop(), do_parking_thread(), pbx_builtin_waitexten(), and wait_for_answer().
02466 { 02467 int res = -1; 02468 02469 ast_channel_lock(chan); 02470 /* Stop if we're a zombie or need a soft hangup */ 02471 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { 02472 ast_channel_unlock(chan); 02473 return -1; 02474 } 02475 if (chan->tech->indicate) 02476 res = chan->tech->indicate(chan, condition, data, datalen); 02477 ast_channel_unlock(chan); 02478 if (!chan->tech->indicate || res) { 02479 /* 02480 * Device does not support (that) indication, lets fake 02481 * it by doing our own tone generation. (PM2002) 02482 */ 02483 if (condition < 0) 02484 ast_playtones_stop(chan); 02485 else { 02486 const struct tone_zone_sound *ts = NULL; 02487 switch (condition) { 02488 case AST_CONTROL_RINGING: 02489 ts = ast_get_indication_tone(chan->zone, "ring"); 02490 break; 02491 case AST_CONTROL_BUSY: 02492 ts = ast_get_indication_tone(chan->zone, "busy"); 02493 break; 02494 case AST_CONTROL_CONGESTION: 02495 ts = ast_get_indication_tone(chan->zone, "congestion"); 02496 break; 02497 } 02498 if (ts && ts->data[0]) { 02499 if (option_debug) 02500 ast_log(LOG_DEBUG, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition); 02501 ast_playtones_start(chan,0,ts->data, 1); 02502 res = 0; 02503 } else if (condition == AST_CONTROL_PROGRESS) { 02504 /* ast_playtones_stop(chan); */ 02505 } else if (condition == AST_CONTROL_PROCEEDING) { 02506 /* Do nothing, really */ 02507 } else if (condition == AST_CONTROL_HOLD) { 02508 /* Do nothing.... */ 02509 } else if (condition == AST_CONTROL_UNHOLD) { 02510 /* Do nothing.... */ 02511 } else if (condition == AST_CONTROL_VIDUPDATE) { 02512 /* Do nothing.... */ 02513 } else { 02514 /* not handled */ 02515 ast_log(LOG_WARNING, "Unable to handle indication %d for '%s'\n", condition, chan->name); 02516 res = -1; 02517 } 02518 } 02519 } 02520 return res; 02521 }
| 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 4396 of file channel.c.
References ast_moh_cleanup_ptr, ast_moh_start_ptr, and ast_moh_stop_ptr.
Referenced by load_module(), and reload().
04399 { 04400 ast_moh_start_ptr = start_ptr; 04401 ast_moh_stop_ptr = stop_ptr; 04402 ast_moh_cleanup_ptr = cleanup_ptr; 04403 }
| int ast_internal_timing_enabled | ( | struct ast_channel * | chan | ) |
Check if the channel can run in internal timing mode.
| chan | The channel to check |
Definition at line 2442 of file channel.c.
References ast_log(), ast_opt_internal_timing, LOG_DEBUG, option_debug, and ast_channel::timingfd.
Referenced by __ast_read(), and add_sdp().
02443 { 02444 int ret = ast_opt_internal_timing && chan->timingfd > -1; 02445 if (option_debug > 4) 02446 ast_log(LOG_DEBUG, "Internal timing is %s (option_internal_timing=%d chan->timingfd=%d)\n", ret? "enabled": "disabled", ast_opt_internal_timing, chan->timingfd); 02447 return ret; 02448 }
| static AST_LIST_HEAD_NOLOCK_STATIC | ( | backends | , | |
| chanlist | ||||
| ) | [static] |
the list of registered channel types
| static AST_LIST_HEAD_STATIC | ( | channels | , | |
| ast_channel | ||||
| ) | [static] |
the list of channels we have. Note that the lock for this list is used for both the channels list and the backends list.
| void ast_moh_cleanup | ( | struct ast_channel * | chan | ) |
Definition at line 4433 of file channel.c.
References ast_moh_cleanup_ptr.
Referenced by ast_channel_free().
04434 { 04435 if (ast_moh_cleanup_ptr) 04436 ast_moh_cleanup_ptr(chan); 04437 }
| 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. |
| 0 | success | |
| non-zero | failure |
Definition at line 4413 of file channel.c.
References ast_moh_start_ptr, ast_verbose(), option_verbose, and VERBOSE_PREFIX_3.
Referenced by alsa_indicate(), app_exec(), conf_run(), feature_exec_app(), gtalk_indicate(), handle_setmusic(), iax2_indicate(), local_indicate(), mgcp_indicate(), misdn_indication(), moh0_exec(), moh1_exec(), moh3_exec(), oh323_indicate(), oss_indicate(), phone_indicate(), queue_exec(), retrydial_exec(), say_periodic_announcement(), say_position(), sip_indicate(), skinny_indicate(), and zt_indicate().
04414 { 04415 if (ast_moh_start_ptr) 04416 return ast_moh_start_ptr(chan, mclass, interpclass); 04417 04418 if (option_verbose > 2) { 04419 ast_verbose(VERBOSE_PREFIX_3 "Music class %s requested but no musiconhold loaded.\n", 04420 mclass ? mclass : (interpclass ? interpclass : "default")); 04421 } 04422 04423 return 0; 04424 }
| 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 4427 of file channel.c.
References ast_moh_stop_ptr.
Referenced by alsa_indicate(), app_exec(), conf_run(), feature_exec_app(), gtalk_indicate(), handle_setmusic(), iax2_indicate(), local_indicate(), mgcp_indicate(), misdn_indication(), misdn_transfer_bc(), moh0_exec(), moh1_exec(), moh4_exec(), oh323_indicate(), oss_indicate(), phone_indicate(), queue_exec(), retrydial_exec(), say_periodic_announcement(), say_position(), sip_indicate(), skinny_indicate(), try_calling(), and zt_indicate().
04428 { 04429 if (ast_moh_stop_ptr) 04430 ast_moh_stop_ptr(chan); 04431 }
| char* ast_print_group | ( | char * | buf, | |
| int | buflen, | |||
| ast_group_t | group | |||
| ) |
print call- and pickup groups into buffer
Definition at line 4445 of file channel.c.
Referenced by _sip_show_peer(), func_channel_read(), misdn_cfg_get_config_string(), print_group(), read_config(), and serialize_showchan().
04446 { 04447 unsigned int i; 04448 int first=1; 04449 char num[3]; 04450 04451 buf[0] = '\0'; 04452 04453 if (!group) /* Return empty string if no group */ 04454 return buf; 04455 04456 for (i = 0; i <= 63; i++) { /* Max group is 63 */ 04457 if (group & ((ast_group_t) 1 << i)) { 04458 if (!first) { 04459 strncat(buf, ", ", buflen); 04460 } else { 04461 first=0; 04462 } 04463 snprintf(num, sizeof(num), "%u", i); 04464 strncat(buf, num, buflen); 04465 } 04466 } 04467 return buf; 04468 }
| int ast_prod | ( | struct ast_channel * | chan | ) |
Send empty audio to prime a channel driver.
Definition at line 2644 of file channel.c.
References ast_channel::_state, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), AST_STATE_UP, ast_write(), ast_frame::data, LOG_DEBUG, LOG_WARNING, option_debug, ast_channel::rawwriteformat, ast_frame::src, and ast_frame::subclass.
Referenced by ast_activate_generator().
02645 { 02646 struct ast_frame a = { AST_FRAME_VOICE }; 02647 char nothing[128]; 02648 02649 /* Send an empty audio frame to get things moving */ 02650 if (chan->_state != AST_STATE_UP) { 02651 if (option_debug) 02652 ast_log(LOG_DEBUG, "Prodding channel '%s'\n", chan->name); 02653 a.subclass = chan->rawwriteformat; 02654 a.data = nothing + AST_FRIENDLY_OFFSET; 02655 a.src = "ast_prod"; 02656 if (ast_write(chan, &a)) 02657 ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", chan->name); 02658 } 02659 return 0; 02660 }
| int ast_queue_control | ( | struct ast_channel * | chan, | |
| enum ast_control_frame_type | control | |||
| ) |
Queue a control frame with payload.
| chan | channel to queue frame onto | |
| control | type of control frame |
Definition at line 948 of file channel.c.
References AST_FRAME_CONTROL, ast_queue_frame(), and f.
Referenced by __oh323_update_info(), __zt_exception(), ast_pickup_call(), attempt_transfer(), auto_congest(), gtalk_is_answered(), gtalk_ringing_ack(), handle_hd_hf(), handle_offhook_message(), handle_request(), handle_request_bye(), handle_request_info(), handle_request_refer(), handle_response(), handle_response_invite(), handle_response_refer(), handle_soft_key_event_message(), handle_stimulus_message(), mgcp_call(), nbs_call(), phone_call(), pickup_do(), process_sdp(), receive_digit(), send_cause2ast(), setup_rtp_connection(), skinny_call(), skinny_unhold(), socket_process(), ss_thread(), update_state(), zt_handle_event(), and zt_hangup().
00949 { 00950 struct ast_frame f = { AST_FRAME_CONTROL, }; 00951 00952 f.subclass = control; 00953 00954 return ast_queue_frame(chan, &f); 00955 }
| 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 |
Definition at line 958 of file channel.c.
References AST_FRAME_CONTROL, ast_queue_frame(), and f.
Referenced by process_sdp(), skinny_hold(), socket_process(), zt_handle_event(), and zt_hangup().
00960 { 00961 struct ast_frame f = { AST_FRAME_CONTROL, }; 00962 00963 f.subclass = control; 00964 f.data = (void *) data; 00965 f.datalen = datalen; 00966 00967 return ast_queue_frame(chan, &f); 00968 }
| int ast_queue_frame | ( | struct ast_channel * | chan, | |
| struct ast_frame * | fin | |||
| ) |
Queue an outgoing frame.
Definition at line 880 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_VOICE, ast_frdup(), ast_frfree(), AST_LIST_INSERT_TAIL, AST_LIST_LAST, AST_LIST_TRAVERSE, ast_log(), ast_test_flag, ast_channel::blocker, CRASH, f, ast_frame::frametype, LOG_DEBUG, LOG_WARNING, option_debug, ast_frame::subclass, and ast_channel::timingfd.
Referenced by __oh323_rtp_create(), __oh323_update_info(), agent_new(), alsa_call(), ast_channel_masquerade(), ast_channel_setwhentohangup(), ast_dsp_process(), ast_queue_control(), ast_queue_control_data(), ast_queue_hangup(), ast_softhangup_nolock(), cb_events(), console_answer(), console_answer_deprecated(), console_dial(), console_dial_deprecated(), console_flash(), console_flash_deprecated(), console_sendtext(), console_sendtext_deprecated(), dictate_exec(), do_immediate_setup(), gtalk_handle_dtmf(), handle_keypad_button_message(), handle_request_info(), handle_request_invite(), handle_response_invite(), iax2_queue_frame(), local_queue_frame(), mgcp_queue_frame(), oh323_simulate_dtmf_end(), oss_call(), process_sdp(), receive_digit(), receive_message(), wakeup_sub(), and zap_queue_frame().
00881 { 00882 struct ast_frame *f; 00883 struct ast_frame *cur; 00884 int blah = 1; 00885 int qlen = 0; 00886 00887 /* Build us a copy and free the original one */ 00888 if (!(f = ast_frdup(fin))) { 00889 ast_log(LOG_WARNING, "Unable to duplicate frame\n"); 00890 return -1; 00891 } 00892 ast_channel_lock(chan); 00893 00894 /* See if the last frame on the queue is a hangup, if so don't queue anything */ 00895 if ((cur = AST_LIST_LAST(&chan->readq)) && (cur->frametype == AST_FRAME_CONTROL) && (cur->subclass == AST_CONTROL_HANGUP)) { 00896 ast_frfree(f); 00897 ast_channel_unlock(chan); 00898 return 0; 00899 } 00900 00901 /* Count how many frames exist on the queue */ 00902 AST_LIST_TRAVERSE(&chan->readq, cur, frame_list) { 00903 qlen++; 00904 } 00905 00906 /* Allow up to 96 voice frames outstanding, and up to 128 total frames */ 00907 if (((fin->frametype == AST_FRAME_VOICE) && (qlen > 96)) || (qlen > 128)) { 00908 if (fin->frametype != AST_FRAME_VOICE) { 00909 ast_log(LOG_WARNING, "Exceptionally long queue length queuing to %s\n", chan->name); 00910 CRASH; 00911 } else { 00912 if (option_debug) 00913 ast_log(LOG_DEBUG, "Dropping voice to exceptionally long queue on %s\n", chan->name); 00914 ast_frfree(f); 00915 ast_channel_unlock(chan); 00916 return 0; 00917 } 00918 } 00919 AST_LIST_INSERT_TAIL(&chan->readq, f, frame_list); 00920 if (chan->alertpipe[1] > -1) { 00921 if (write(chan->alertpipe[1], &blah, sizeof(blah)) != sizeof(blah)) 00922 ast_log(LOG_WARNING, "Unable to write to alert pipe on %s, frametype/subclass %d/%d (qlen = %d): %s!\n", 00923 chan->name, f->frametype, f->subclass, qlen, strerror(errno)); 00924 #ifdef HAVE_ZAPTEL 00925 } else if (chan->timingfd > -1) { 00926 ioctl(chan->timingfd, ZT_TIMERPING, &blah); 00927 #endif 00928 } else if (ast_test_flag(chan, AST_FLAG_BLOCKING)) { 00929 pthread_kill(chan->blocker, SIGURG); 00930 } 00931 ast_channel_unlock(chan); 00932 return 0; 00933 }
| int ast_queue_hangup | ( | struct ast_channel * | chan | ) |
Queue a hangup frame.
Definition at line 936 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, and f.
Referenced by __oh323_update_info(), __sip_autodestruct(), cleanup_connection(), console_hangup(), console_hangup_deprecated(), gtalk_hangup_farend(), handle_onhook_message(), handle_request_bye(), handle_request_cancel(), handle_response(), handle_response_invite(), handle_soft_key_event_message(), hangup_chan(), hangup_connection(), iax2_destroy(), iax2_predestroy(), mgcp_queue_hangup(), misdn_answer(), retrans_pkt(), and zt_handle_event().
00937 { 00938 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; 00939 /* Yeah, let's not change a lock-critical value without locking */ 00940 if (!ast_channel_trylock(chan)) { 00941 chan->_softhangup |= AST_SOFTHANGUP_DEV; 00942 ast_channel_unlock(chan); 00943 } 00944 return ast_queue_frame(chan, &f); 00945 }
| struct ast_frame* ast_read | ( | struct ast_channel * | chan | ) |
Reads a frame.
| chan | channel to read a frame from |
Definition at line 2450 of file channel.c.
References __ast_read().
Referenced by __adsi_transmit_messages(), __ast_play_and_record(), __ast_request_and_dial(), adsi_careful_send(), agent_ack_sleep(), agent_read(), app_exec(), ast_feature_request_and_dial(), ast_masq_park_call(), 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(), dictate_exec(), disa_exec(), do_parking_thread(), do_waiting(), echo_exec(), features_read(), find_cache(), handle_invite_replaces(), handle_recordfile(), iax_park_thread(), ices_exec(), isAnsweringMachine(), measurenoise(), misdn_bridge(), monitor_dial(), mp3_exec(), mwanalyze_exec(), NBScat_exec(), nv_background_detect_exec(), nv_detectfax_exec(), receive_dtmf_digits(), recordthread(), rpt(), run_agi(), rxfax_exec(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), speech_background(), ss_thread(), txfax_exec(), wait_for_answer(), wait_for_hangup(), wait_for_winner(), waitforring_exec(), waitstream_core(), and zt_bridge().
02451 { 02452 return __ast_read(chan, 0); 02453 }
| struct ast_frame* ast_read_noaudio | ( | struct ast_channel * | chan | ) |
Reads a frame, returning AST_FRAME_NULL frame if audio.
| chan | channel to read a frame from |
Definition at line 2455 of file channel.c.
References __ast_read().
Referenced by conf_run().
02456 { 02457 return __ast_read(chan, 1); 02458 }
| 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 3147 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().
03148 { 03149 return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1); 03150 }
| 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 3152 of file channel.c.
References ast_check_hangup(), AST_DIGIT_ANY, AST_FLAG_ZOMBIE, ast_stopstream(), ast_test_flag, ast_waitfordigit_full(), ast_waitstream_full(), and ast_channel::stream.
Referenced by ast_app_getdata_full(), and ast_readstring().
03153 { 03154 int pos = 0; /* index in the buffer where we accumulate digits */ 03155 int to = ftimeout; 03156 03157 /* Stop if we're a zombie or need a soft hangup */ 03158 if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c)) 03159 return -1; 03160 if (!len) 03161 return -1; 03162 for (;;) { 03163 int d; 03164 if (c->stream) { 03165 d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd); 03166 ast_stopstream(c); 03167 usleep(1000); 03168 if (!d) 03169 d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); 03170 } else { 03171 d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); 03172 } 03173 if (d < 0) 03174 return -1; 03175 if (d == 0) { 03176 s[pos]='\0'; 03177 return 1; 03178 } 03179 if (d == 1) { 03180 s[pos]='\0'; 03181 return 2; 03182 } 03183 if (!strchr(enders, d)) 03184 s[pos++] = d; 03185 if (strchr(enders, d) || (pos >= len)) { 03186 s[pos]='\0'; 03187 return 0; 03188 } 03189 to = timeout; 03190 } 03191 /* Never reached */ 03192 return 0; 03193 }
| 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 2523 of file channel.c.
References ast_recvtext(), and free.
Referenced by handle_recvchar().
02524 { 02525 int c; 02526 char *buf = ast_recvtext(chan, timeout); 02527 if (buf == NULL) 02528 return -1; /* error or timeout */ 02529 c = *(unsigned char *)buf; 02530 free(buf); 02531 return c; 02532 }
| 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 2534 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(), and f.
Referenced by ast_recvchar(), and handle_recvtext().
02535 { 02536 int res, done = 0; 02537 char *buf = NULL; 02538 02539 while (!done) { 02540 struct ast_frame *f; 02541 if (ast_check_hangup(chan)) 02542 break; 02543 res = ast_waitfor(chan, timeout); 02544 if (res <= 0) /* timeout or error */ 02545 break; 02546 timeout = res; /* update timeout */ 02547 f = ast_read(chan); 02548 if (f == NULL) 02549 break; /* no frame */ 02550 if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) 02551 done = 1; /* force a break */ 02552 else if (f->frametype == AST_FRAME_TEXT) { /* what we want */ 02553 buf = ast_strndup((char *) f->data, f->datalen); /* dup and break */ 02554 done = 1; 02555 } 02556 ast_frfree(f); 02557 } 02558 return buf; 02559 }
| struct ast_channel* ast_request | ( | const char * | type, | |
| int | format, | |||
| void * | data, | |||
| int * | status | |||
| ) |
Requests a channel.
| type | type of channel to request | |
| format | requested channel format (codec) | |
| data | data to pass to the channel requester | |
| status | status Request a channel of a given type, with data as optional information used by the low level module |
Definition at line 3056 of file channel.c.
References AST_CAUSE_NOSUCHDRIVER, AST_CAUSE_NOTDEFINED, AST_FORMAT_AUDIO_MASK, AST_FORMAT_VIDEO_MASK, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_translator_best_choice(), capabilities, ast_channel_tech::capabilities, fmt, LOG_WARNING, ast_channel_tech::requester, chanlist::tech, and ast_channel_tech::type.
Referenced by __ast_request_and_dial(), agent_request(), ast_feature_request_and_dial(), ast_request_inherit(), attempt_reconnect(), begin_dial(), build_conf(), chanavail_exec(), conf_run(), features_alloc(), findmeexec(), function_ilink(), ring_entry(), rpt(), rpt_call(), rpt_exec(), rpt_tele_thread(), and wait_for_answer().
03057 { 03058 struct chanlist *chan; 03059 struct ast_channel *c; 03060 int capabilities; 03061 int fmt; 03062 int res; 03063 int foo; 03064 int videoformat = format & AST_FORMAT_VIDEO_MASK; 03065 03066 if (!cause) 03067 cause = &foo; 03068 *cause = AST_CAUSE_NOTDEFINED; 03069 03070 if (AST_LIST_LOCK(&channels)) { 03071 ast_log(LOG_WARNING, "Unable to lock channel list\n"); 03072 return NULL; 03073 } 03074 03075 AST_LIST_TRAVERSE(&backends, chan, list) { 03076 if (strcasecmp(type, chan->tech->type)) 03077 continue; 03078 03079 capabilities = chan->tech->capabilities; 03080 fmt = format & AST_FORMAT_AUDIO_MASK; 03081 res = ast_translator_best_choice(&fmt, &capabilities); 03082 if (res < 0) { 03083 ast_log(LOG_WARNING, "No translator path exists for channel type %s (native %d) to %d\n", type, chan->tech->capabilities, format); 03084 AST_LIST_UNLOCK(&channels); 03085 return NULL; 03086 } 03087 AST_LIST_UNLOCK(&channels); 03088 if (!chan->tech->requester) 03089 return NULL; 03090 03091 if (!(c = chan->tech->requester(type, capabilities | videoformat, data, cause))) 03092 return NULL; 03093 03094 /* no need to generate a Newchannel event here; it is done in the channel_alloc call */ 03095 return c; 03096 } 03097 03098 ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type); 03099 *cause = AST_CAUSE_NOSUCHDRIVER; 03100 AST_LIST_UNLOCK(&channels); 03101 03102 return NULL; 03103 }
| struct ast_channel* ast_request_and_dial | ( | const char * | type, | |
| int | format, | |||
| void * | data, | |||
| int | timeout, | |||
| int * | reason, | |||
| 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.
| 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 unsuceessful) | |
| cidnum | Caller-ID Number | |
| cidname | Caller-ID Name |
Definition at line 3051 of file channel.c.
References __ast_request_and_dial().
Referenced by ast_pbx_outgoing_exten().
03052 { 03053 return __ast_request_and_dial(type, format, data, timeout, outstate, cidnum, cidname, NULL); 03054 }
| int ast_safe_sleep | ( | struct ast_channel * | chan, | |
| int | ms | |||
| ) |
Wait for a specied amount of time, looking for hangups.
| chan | channel to wait for | |
| ms | length of time in milliseconds to sleep Waits for a specified amount of time, servicing the channel as required. |
Definition at line 1132 of file channel.c.
References ast_safe_sleep_conditional().
Referenced by __login_exec(), alarmreceiver_exec(), ast_adsi_transmit_message_full(), ast_dtmf_stream(), ast_senddigit(), builtin_parkcall(), dictate_exec(), flash_exec(), function_ilink(), function_remote(), handle_remote_data(), handle_remote_phone_dtmf(), milliwatt_exec(), moh0_exec(), moh1_exec(), park_call_exec(), pbx_builtin_answer(), pbx_builtin_wait(), play_tone_pair(), playtone(), privacy_exec(), receive_ademco_contact_id(), rmt_telem_start(), rpt_call(), rpt_exec(), rpt_tele_thread(), send_morse(), send_tone_telemetry(), skinny_ss(), ss_thread(), test1_client(), test1_server(), testclient_exec(), testserver_exec(), try_calling(), wait_for_hangup(), wait_interval(), and zapateller_exec().
01133 { 01134 return ast_safe_sleep_conditional(chan, ms, NULL, NULL); 01135 }
| int ast_safe_sleep_conditional | ( | struct ast_channel * | chan, | |
| int | ms, | |||
| int(*)(void *) | cond, | |||
| void * | data | |||
| ) |
Wait for a specied amount of time, looking for hangups and a condition argument.
| chan | channel to wait for | |
| ms | length of time in milliseconds to sleep | |
| cond | a function pointer for testing continue condition | |
| data | argument to be passed to the condition test function |
Definition at line 1111 of file channel.c.
References ast_frfree(), ast_read(), ast_waitfor(), and f.
Referenced by __login_exec(), and ast_safe_sleep().
01112 { 01113 struct ast_frame *f; 01114 01115 while (ms > 0) { 01116 if (cond && ((*cond)(data) == 0)) 01117 return 0; 01118 ms = ast_waitfor(chan, ms); 01119 if (ms < 0) 01120 return -1; 01121 if (ms > 0) { 01122 f = ast_read(chan); 01123 if (!f) 01124 return -1; 01125 ast_frfree(f); 01126 } 01127 } 01128 return 0; 01129 }
| char* ast_safe_string_alloc | ( | const char * | fmt, | |
| ... | ||||
| ) |
printf the string into a correctly sized mallocd buffer, and return the buffer
return a mallocd string with the result of sprintf of the fmt and following args
Definition at line 426 of file channel.c.
References ast_malloc, and len.
Referenced by features_new().
00427 { 00428 char *b2,buf[1]; 00429 int len; 00430 00431 va_list args; 00432 va_start(args, fmt); 00433 len = vsnprintf(buf, 1, fmt, args); 00434 b2 = ast_malloc(len+1); 00435 vsnprintf(b2, len+1, fmt, args); 00436 va_end(args); 00437 return b2; 00438 }
| int ast_say_character_str | ( | struct ast_channel * | chan, | |
| const char * | str, | |||
| const char * | ints, | |||
| const char * | lang | |||
| ) |
Definition at line 4840 of file channel.c.
References ast_say_character_str_full.
Referenced by common_exec(), pbx_builtin_saycharacters(), play_mailbox_owner(), rpt_tele_thread(), and saycharstr().
04842 { 04843 return ast_say_character_str_full(chan, str, ints, lang, -1, -1); 04844 }
| int ast_say_digit_str | ( | struct ast_channel * | chan, | |
| const char * | str, | |||
| const char * | ints, | |||
| const char * | lang | |||
| ) |
Definition at line 4834 of file channel.c.
References ast_say_digit_str_full.
Referenced by invent_message(), mgcp_ss(), pbx_builtin_saydigits(), play_message_callerid(), and ss_thread().
04836 { 04837 return ast_say_digit_str_full(chan, str, ints, lang, -1, -1); 04838 }
| int ast_say_digits | ( | struct ast_channel * | chan, | |
| int | num, | |||
| const char * | ints, | |||
| const char * | lang | |||
| ) |
Definition at line 4828 of file channel.c.
References ast_say_digits_full().
Referenced by ast_park_call(), common_exec(), conf_exec(), parkandannounce_exec(), and rpt_tele_thread().
04830 { 04831 return ast_say_digits_full(chan, num, ints, lang, -1, -1); 04832 }
| int ast_say_digits_full | ( | struct ast_channel * | chan, | |
| int | num, | |||
| const char * | ints, | |||
| const char * | lang, | |||
| int | audiofd, | |||
| int | ctrlfd | |||
| ) |
Definition at line 4852 of file channel.c.
References ast_say_digit_str_full.
Referenced by __say_init(), ast_say_digits(), ast_say_enumeration_full_da(), ast_say_enumeration_full_de(), ast_say_number_full_cz(), 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_ge(), ast_say_number_full_he(), ast_say_number_full_it(), 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(), and ast_say_number_full_tw().
04854 { 04855 char buf[256]; 04856 04857 snprintf(buf, sizeof(buf), "%d", num); 04858 return ast_say_digit_str_full(chan, buf, ints, lang, audiofd, ctrlfd); 04859 }
| int ast_say_enumeration | ( | struct ast_channel * | chan, | |
| int | num, | |||
| const char * | ints, | |||
| const char * | language, | |||
| const char * | options | |||
| ) |
Definition at line 4822 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().
04824 { 04825 return ast_say_enumeration_full(chan, num, ints, language, options, -1, -1); 04826 }
| int ast_say_number | ( | struct ast_channel * | chan, | |
| int | num, | |||
| const char * | ints, | |||
| const char * | language, | |||
| const char * | options | |||
| ) |
Definition at line 4816 of file channel.c.
References ast_say_number_full.
Referenced by ast_say_date_da(), ast_say_date_de(), ast_say_date_en(), ast_say_date_fr(), ast_say_date_ge(), ast_say_date_gr(), ast_say_date_nl(), ast_say_date_pt(), 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_datetime_en(), ast_say_datetime_fr(), ast_say_datetime_from_now_en(), ast_say_datetime_from_now_fr(), ast_say_datetime_from_now_ge(), ast_say_datetime_from_now_pt(), ast_say_datetime_pt(), ast_say_datetime_tw(), ast_say_time_de(), ast_say_time_en(), ast_say_time_fr(), ast_say_time_ge(), ast_say_time_gr(), ast_say_time_nl(), ast_say_time_pt(), ast_say_time_pt_BR(), ast_say_time_tw(), 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_pt(), and vm_intro_pt_BR().
04818 { 04819 return ast_say_number_full(chan, num, ints, language, options, -1, -1); 04820 }
| int ast_say_phonetic_str | ( | struct ast_channel * | chan, | |
| const char * | str, | |||
| const char * | ints, | |||
| const char * | lang | |||
| ) |
Definition at line 4846 of file channel.c.
References ast_say_phonetic_str_full.
Referenced by pbx_builtin_sayphonetic().
04848 { 04849 return ast_say_phonetic_str_full(chan, str, ints, lang, -1, -1); 04850 }
| int ast_senddigit | ( | 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 2634 of file channel.c.
References AST_FLAG_END_DTMF_ONLY, ast_safe_sleep(), ast_senddigit_begin(), ast_senddigit_end(), and ast_test_flag.
Referenced by ast_dtmf_stream(), and manager_play_dtmf().
02635 { 02636 if (!ast_test_flag(chan, AST_FLAG_END_DTMF_ONLY)) { 02637 ast_senddigit_begin(chan, digit); 02638 ast_safe_sleep(chan, 100); /* XXX 100ms ... probably should be configurable */ 02639 } 02640 02641 return ast_senddigit_end(chan, digit, 100); 02642 }
| 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 2574 of file channel.c.
References ast_log(), ast_playtones_start(), LOG_DEBUG, option_debug, ast_channel_tech::send_digit_begin, and ast_channel::tech.
Referenced by agent_digit_begin(), ast_senddigit(), ast_write(), and features_digit_begin().
02575 { 02576 int res = -1; 02577 02578 if (chan->tech->send_digit_begin) 02579 res = chan->tech->send_digit_begin(chan, digit); 02580 02581 if (res) { 02582 /* 02583 * Device does not support DTMF tones, lets fake 02584 * it by doing our own generation. (PM2002) 02585 */ 02586 static const char* dtmf_tones[] = { 02587 "!941+1336/100,!0/100", /* 0 */ 02588 "!697+1209/100,!0/100", /* 1 */ 02589 "!697+1336/100,!0/100", /* 2 */ 02590 "!697+1477/100,!0/100", /* 3 */ 02591 "!770+1209/100,!0/100", /* 4 */ 02592 "!770+1336/100,!0/100", /* 5 */ 02593 "!770+1477/100,!0/100", /* 6 */ 02594 "!852+1209/100,!0/100", /* 7 */ 02595 "!852+1336/100,!0/100", /* 8 */ 02596 "!852+1477/100,!0/100", /* 9 */ 02597 "!697+1633/100,!0/100", /* A */ 02598 "!770+1633/100,!0/100", /* B */ 02599 "!852+1633/100,!0/100", /* C */ 02600 "!941+1633/100,!0/100", /* D */ 02601 "!941+1209/100,!0/100", /* * */ 02602 "!941+1477/100,!0/100" }; /* # */ 02603 if (digit >= '0' && digit <='9') 02604 ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0); 02605 else if (digit >= 'A' && digit <= 'D') 02606 ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0); 02607 else if (digit == '*') 02608 ast_playtones_start(chan, 0, dtmf_tones[14], 0); 02609 else if (digit == '#') 02610 ast_playtones_start(chan, 0, dtmf_tones[15], 0); 02611 else { 02612 /* not handled */ 02613 if (option_debug) 02614 ast_log(LOG_DEBUG, "Unable to generate DTMF tone '%c' for '%s'\n", digit, chan->name); 02615 } 02616 } 02617 02618 return 0; 02619 }
| 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 |
Definition at line 2621 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(), ast_write(), and features_digit_end().
02622 { 02623 int res = -1; 02624 02625 if (chan->tech->send_digit_end) 02626 res = chan->tech->send_digit_end(chan, digit, duration); 02627 02628 if (res && chan->generator) 02629 ast_playtones_stop(chan); 02630 02631 return 0; 02632 }
| int ast_sendtext | ( | struct ast_channel * | chan, | |
| const char * | text | |||
| ) |
Sends text to a channel Write text to a display on a channel.
| chan | channel to act upon | |
| text | string of text to send on the channel |
Definition at line 2561 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 agent_sendtext(), handle_sendtext(), and sendtext_exec().
02562 { 02563 int res = 0; 02564 /* Stop if we're a zombie or need a soft hangup */ 02565 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) 02566 return -1; 02567 CHECK_BLOCKING(chan); 02568 if (chan->tech->send_text) 02569 res = chan->tech->send_text(chan, text); 02570 ast_clear_flag(chan, AST_FLAG_BLOCKING); 02571 return res; 02572 }
| void ast_set_callerid | ( | struct ast_channel * | chan, | |
| const char * | callerid, | |||
| const char * | calleridname, | |||
| const char * | ani | |||
| ) |
Definition at line 3688 of file channel.c.
References ast_cdr_setcid(), ast_describe_caller_presentation(), ast_strdup, ast_channel::cdr, ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_name, ast_callerid::cid_num, ast_callerid::cid_pres, EVENT_FLAG_CALL, free, manager_event(), and S_OR.
Referenced by __ast_request_and_dial(), agent_call(), ast_feature_request_and_dial(), callerid_write(), disa_exec(), findmeexec(), handle_setcallerid(), lookupcidname_exec(), mgcp_ss(), privacy_exec(), read_config(), rpt_exec(), setcallerid_exec(), skinny_newcall(), ss_thread(), wait_for_answer(), and zt_read().
03689 { 03690 if (callerid) { 03691 if (chan->cid.cid_num) 03692 free(chan->cid.cid_num); 03693 chan->cid.cid_num = ast_strdup(callerid); 03694 } 03695 if (calleridname) { 03696 if (chan->cid.cid_name) 03697 free(chan->cid.cid_name); 03698 chan->cid.cid_name = ast_strdup(calleridname); 03699 } 03700 if (ani) { 03701 if (chan->cid.cid_ani) 03702 free(chan->cid.cid_ani); 03703 chan->cid.cid_ani = ast_strdup(ani); 03704 } 03705 if (chan->cdr) 03706 ast_cdr_setcid(chan->cdr, chan); 03707 manager_event(EVENT_FLAG_CALL, "Newcallerid", 03708 "Channel: %s\r\n" 03709 "CallerID: %s\r\n" 03710 "CallerIDName: %s\r\n" 03711 "Uniqueid: %s\r\n" 03712 "CID-CallingPres: %d (%s)\r\n", 03713 chan->name, 03714 S_OR(chan->cid.cid_num, "<Unknown>"), 03715 S_OR(chan->cid.cid_name, "<Unknown>"), 03716 chan->uniqueid, 03717 chan->cid.cid_pres, 03718 ast_describe_caller_presentation(chan->cid.cid_pres) 03719 ); 03720 }
| 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 2915 of file channel.c.
References ast_channel::rawreadformat, ast_channel::readformat, ast_channel::readtrans, and set_format().
Referenced by __ast_play_and_record(), __login_exec(), __oh323_update_info(), agent_call(), alarmreceiver_exec(), ast_adsi_transmit_message_full(), ast_channel_formats_reset(), ast_channel_make_compatible(), ast_set_best_format(), attempt_reconnect(), background_detect_exec(), build_conf(), conf_run(), dictate_exec(), disa_exec(), do_waiting(), eagi_exec(), echo_exec(), function_ilink(), gtalk_rtp_read(), handle_recordfile(), ices_exec(), isAnsweringMachine(), measurenoise(), mgcp_rtp_read(), milliwatt_exec(), mwanalyze_exec(), nv_background_detect_exec(), nv_detectfax_exec(), oh323_rtp_read(), process_sdp(), rpt(), rpt_exec(), rxfax_exec(), setup_rtp_connection(), sip_rtp_read(), skinny_rtp_read(), socket_process(), speech_background(), txfax_exec(), and update_features().
02916 { 02917 return set_format(chan, fmt, &chan->rawreadformat, &chan->readformat, 02918 &chan->readtrans, 0); 02919 }
| void ast_set_variables | ( | struct ast_channel * | chan, | |
| struct ast_variable * | vars | |||
| ) |
adds a list of channel variables to a channel
| chan | the channel | |
| vars | a linked list of variables |
Definition at line 4470 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_pbx_outgoing_app(), and ast_pbx_outgoing_exten().
04471 { 04472 struct ast_variable *cur; 04473 04474 for (cur = vars; cur; cur = cur->next) 04475 pbx_builtin_setvar_helper(chan, cur->name, cur->value); 04476 }
| int ast_set_write_format | ( | struct ast_channel * | chan, | |
| int | format | |||
| ) |
Sets write format on channel chan Set write format for channel to whichever compoent of "format" is best.
| chan | channel to change | |
| format | new format for writing |
Definition at line 2921 of file channel.c.
References ast_channel::rawwriteformat, set_format(), ast_channel::writeformat, and ast_channel::writetrans.
Referenced by __login_exec(), __oh323_update_info(), agent_call(), alarmreceiver_exec(), ast_adsi_transmit_message_full(), ast_channel_formats_reset(), ast_channel_make_compatible(), ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_channel_whisper_stop(), ast_openstream_full(), ast_set_best_format(), ast_stopstream(), ast_write(), attempt_reconnect(), build_conf(), channel_spy(), chanspy_exec(), conf_run(), disa_exec(), echo_exec(), extenspy_exec(), function_ilink(), gtalk_rtp_read(), linear_alloc(), linear_release(), mgcp_rtp_read(), milliwatt_exec(), moh_alloc(), moh_files_release(), moh_release(), mp3_exec(), mwanalyze_exec(), NBScat_exec(), oh323_rtp_read(), playtones_alloc(), playtones_release(), process_sdp(), rpt(), rpt_exec(), rxfax_exec(), send_waveform_to_channel(), setup_rtp_connection(), sip_rtp_read(), skinny_rtp_read(), socket_process(), tonepair_alloc(), tonepair_release(), txfax_exec(), and update_features().
02922 { 02923 return set_format(chan, fmt, &chan->rawwriteformat, &chan->writeformat, 02924 &chan->writetrans, 1); 02925 }
| int ast_setstate | ( | struct ast_channel * | chan, | |
| enum ast_channel_state | state | |||
| ) |
Change the state of a channel.
Definition at line 3722 of file channel.c.
References ast_channel::_state, ast_device_state_changed_literal(), ast_state2str(), ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, EVENT_FLAG_CALL, manager_event(), and S_OR.
Referenced by __ast_read(), __oh323_update_info(), __zt_exception(), agent_call(), alsa_answer(), ast_answer(), cb_events(), check_availability(), 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(), 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(), sip_answer(), skinny_answer(), skinny_call(), skinny_newcall(), ss_thread(), update_state(), zt_answer(), zt_call(), zt_handle_event(), zt_indicate(), and zt_read().
03723 { 03724 int oldstate = chan->_state; 03725 03726 if (oldstate == state) 03727 return 0; 03728 03729 chan->_state = state; 03730 ast_device_state_changed_literal(chan->name); 03731 /* setstate used to conditionally report Newchannel; this is no more */ 03732 manager_event(EVENT_FLAG_CALL, 03733 "Newstate", 03734 "Channel: %s\r\n" 03735 "State: %s\r\n" 03736 "CallerID: %s\r\n" 03737 "CallerIDName: %s\r\n" 03738 "Uniqueid: %s\r\n", 03739 chan->name, ast_state2str(chan->_state), 03740 S_OR(chan->cid.cid_num, "<unknown>"), 03741 S_OR(chan->cid.cid_name, "<unknown>"), 03742 chan->uniqueid); 03743 03744 return 0; 03745 }
| int ast_settimeout | ( | struct ast_channel * | c, | |
| int | samples, | |||
| int(*)(void *data) | func, | |||
| void * | data | |||
| ) |
Definition at line 2018 of file channel.c.
References ast_log(), LOG_DEBUG, option_debug, ast_channel::timingdata, ast_channel::timingfd, and ast_channel::timingfunc.
Referenced by __ast_read(), ast_activate_generator(), ast_closestream(), ast_deactivate_generator(), and ast_readaudio_callback().
02019 { 02020 int res = -1; 02021 #ifdef HAVE_ZAPTEL 02022 if (c->timingfd > -1) { 02023 if (!func) { 02024 samples = 0; 02025 data = 0; 02026 } 02027 if (option_debug) 02028 ast_log(LOG_DEBUG, "Scheduling timer at %d sample intervals\n", samples); 02029 res = ioctl(c->timingfd, ZT_TIMERCONFIG, &samples); 02030 c->timingfunc = func; 02031 c->timingdata = data; 02032 } 02033 #endif 02034 return res; 02035 }
| 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 472 of file channel.c.
References shutting_down.
00473 { 00474 return shutting_down; 00475 }
| int ast_softhangup | ( | struct ast_channel * | chan, | |
| int | cause | |||
| ) |
Softly hangup up a channel.
| chan | channel to be soft-hung-up Call the protocol layer, but don't destroy the channel structure (use this if you are trying to safely hangup a channel managed by another thread. | |
| cause | Ast hangupcause for hangup |
Definition at line 1522 of file channel.c.
References ast_channel_lock, ast_channel_unlock, ast_softhangup_nolock(), and ast_channel_spy::chan.
Referenced by __ast_module_user_hangup_all(), __unload_module(), action_hangup(), agent_hangup(), agent_logoff(), ast_begin_shutdown(), function_ilink(), handle_hangup(), handle_link_data(), handle_softhangup(), manager_park(), read_agent_config(), rpt(), rpt_call(), rpt_do_restart(), sla_handle_hold_event(), softhangup_exec(), start_spying(), startmon(), unload_module(), and zt_handle_event().
01523 { 01524 int res; 01525 ast_channel_lock(chan); 01526 res = ast_softhangup_nolock(chan, cause); 01527 ast_channel_unlock(chan); 01528 return res; 01529 }
| int ast_softhangup_nolock | ( | struct ast_channel * | chan, | |
| int | cause | |||
| ) |
Softly hangup up a channel (no channel lock).
| chan | channel to be soft-hung-up | |
| cause | Ast hangupcause for hangup (see cause.h) |
Definition at line 1508 of file channel.c.
References ast_channel::_softhangup, AST_FLAG_BLOCKING, ast_log(), ast_null_frame, ast_queue_frame(), ast_test_flag, ast_channel::blocker, ast_channel_spy::chan, LOG_DEBUG, and option_debug.
Referenced by ast_async_goto(), ast_softhangup(), attempt_transfer(), do_monitor(), oh323_indicate(), sip_indicate(), and skinny_indicate().
01509 { 01510 if (option_debug) 01511 ast_log(LOG_DEBUG, "Soft-Hanging up channel '%s'\n", chan->name); 01512 /* Inform channel driver that we need to be hung up, if it cares */ 01513 chan->_softhangup |= cause; 01514 ast_queue_frame(chan, &ast_null_frame); 01515 /* Interrupt any poll call or such */ 01516 if (ast_test_flag(chan, AST_FLAG_BLOCKING)) 01517 pthread_kill(chan->blocker, SIGURG); 01518 return 0; 01519 }
| char* ast_state2str | ( | enum | ast_channel_state | ) |
Gives the string form of a given channel state.
| ast_channel_state | state to get the name of Give a name to a state Returns the text form of the binary state given |
Definition at line 611 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, and STATE2STR_BUFSIZE.
Referenced by action_status(), agent_hangup(), ast_setstate(), attempt_transfer(), func_channel_read(), handle_chanlist(), handle_chanlist_deprecated(), handle_invite_replaces(), handle_showchan(), handle_showchan_deprecated(), local_attended_transfer(), mgcp_new(), serialize_showchan(), and sip_hangup().
00612 { 00613 char *buf; 00614 00615 switch(state) { 00616 case AST_STATE_DOWN: 00617 return "Down"; 00618 case AST_STATE_RESERVED: 00619 return "Rsrvd"; 00620 case AST_STATE_OFFHOOK: 00621 return "OffHook"; 00622 case AST_STATE_DIALING: 00623 return "Dialing"; 00624 case AST_STATE_RING: 00625 return "Ring"; 00626 case AST_STATE_RINGING: 00627 return "Ringing"; 00628 case AST_STATE_UP: 00629 return "Up"; 00630 case AST_STATE_BUSY: 00631 return "Busy"; 00632 case AST_STATE_DIALING_OFFHOOK: 00633 return "Dialing Offhook"; 00634 case AST_STATE_PRERING: 00635 return "Pre-ring"; 00636 default: 00637 if (!(buf = ast_threadstorage_get(&state2str_threadbuf, STATE2STR_BUFSIZE))) 00638 return "Unknown"; 00639 snprintf(buf, STATE2STR_BUFSIZE, "Unknown (%d)", state); 00640 return buf; 00641 } 00642 }
| int ast_str2cause | ( | const char * | name | ) |
Convert a symbolic hangup cause to number.
| name | string form of the cause Returns the cause code |
Definition at line 599 of file channel.c.
References causes.
Referenced by pbx_builtin_hangup().
00600 { 00601 int x; 00602 00603 for (x = 0; x < sizeof(causes) / sizeof(causes[0]); x++) 00604 if (strncasecmp(causes[x].name, name, strlen(causes[x].name)) == 0) 00605 return causes[x].cause; 00606 00607 return -1; 00608 }
| AST_THREADSTORAGE | ( | state2str_threadbuf | , | |
| state2str_threadbuf_init | ||||
| ) |
| 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 4345 of file channel.c.
References ast_frfree(), ast_read(), ast_tonepair_start(), ast_waitfor(), f, and ast_channel::generatordata.
Referenced by zapateller_exec().
04346 { 04347 int res; 04348 04349 if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol))) 04350 return res; 04351 04352 /* Give us some wiggle room */ 04353 while (chan->generatordata && ast_waitfor(chan, 100) >= 0) { 04354 struct ast_frame *f = ast_read(chan); 04355 if (f) 04356 ast_frfree(f); 04357 else 04358 return -1; 04359 } 04360 return 0; 04361 }
| int ast_tonepair_start | ( | struct ast_channel * | chan, | |
| int | freq1, | |||
| int | freq2, | |||
| int | duration, | |||
| int | vol | |||
| ) |
Start a tone going
Definition at line 4327 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(), play_dialtone(), play_tone_pair(), rpt_tele_thread(), and sendnoise().
04328 { 04329 struct tonepair_def d = { 0, }; 04330 04331 d.freq1 = freq1; 04332 d.freq2 = freq2; 04333 d.duration = duration; 04334 d.vol = (vol < 1) ? 8192 : vol; /* force invalid to 8192 */ 04335 if (ast_activate_generator(chan, &tonepair, &d)) 04336 return -1; 04337 return 0; 04338 }
| void ast_tonepair_stop | ( | struct ast_channel * | chan | ) |
Stop a tone from playing
Definition at line 4340 of file channel.c.
References ast_deactivate_generator().
Referenced by sendnoise().
04341 { 04342 ast_deactivate_generator(chan); 04343 }
| int ast_transfer | ( | struct ast_channel * | chan, | |
| char * | dest | |||
| ) |
Transfer a channel (if supported). Returns -1 on error, 0 if not supported and 1 if supported and requested.
Called by:
Definition at line 3129 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().
03130 { 03131 int res = -1; 03132 03133 /* Stop if we're a zombie or need a soft hangup */ 03134 ast_channel_lock(chan); 03135 if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) { 03136 if (chan->tech->transfer) { 03137 res = chan->tech->transfer(chan, dest); 03138 if (!res) 03139 res = 1; 03140 } else 03141 res = 0; 03142 } 03143 ast_channel_unlock(chan); 03144 return res; 03145 }
| char* ast_transfercapability2str | ( | int | transfercapability | ) | const |
Gives the string form of a given transfer capability.
| transfercapability | transfercapabilty to get the name of Give a name to a transfercapbility See above Returns the text form of the binary transfer capbility |
Definition at line 645 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(), misdn_call(), oh323_call(), zt_call(), and zt_new().
00646 { 00647 switch(transfercapability) { 00648 case AST_TRANS_CAP_SPEECH: 00649 return "SPEECH"; 00650 case AST_TRANS_CAP_DIGITAL: 00651 return "DIGITAL"; 00652 case AST_TRANS_CAP_RESTRICTED_DIGITAL: 00653 return "RESTRICTED_DIGITAL"; 00654 case AST_TRANS_CAP_3_1K_AUDIO: 00655 return "3K1AUDIO"; 00656 case AST_TRANS_CAP_DIGITAL_W_TONES: 00657 return "DIGITAL_W_TONES"; 00658 case AST_TRANS_CAP_VIDEO: 00659 return "VIDEO"; 00660 default: 00661 return "UNKNOWN"; 00662 } 00663 }
| void ast_uninstall_music_functions | ( | void | ) |
Definition at line 4405 of file channel.c.
References ast_moh_cleanup_ptr, ast_moh_start_ptr, and ast_moh_stop_ptr.
04406 { 04407 ast_moh_start_ptr = NULL; 04408 ast_moh_stop_ptr = NULL; 04409 ast_moh_cleanup_ptr = NULL; 04410 }
| 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 2002 of file channel.c.
References ast_waitfor_nandfds().
Referenced by __adsi_transmit_messages(), __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(), ices_exec(), isAnsweringMachine(), measurenoise(), mp3_exec(), mwanalyze_exec(), NBScat_exec(), nv_background_detect_exec(), nv_detectfax_exec(), receive_dtmf_digits(), recordthread(), rxfax_exec(), send_tone_burst(), send_waveform_to_channel(), sendurl_exec(), speech_background(), ss_thread(), txfax_exec(), wait_for_hangup(), waitforring_exec(), and waitstream_core().
02003 { 02004 int oldms = ms; /* -1 if no timeout */ 02005 02006 ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms); 02007 if ((ms < 0) && (oldms < 0)) 02008 ms = 0; 02009 return ms; 02010 }
| struct ast_channel* ast_waitfor_n | ( | struct ast_channel ** | chan, | |
| int | n, | |||
| int * | ms | |||
| ) |
Waits for input on a group of channels Wait for input on an array of channels for a given # of milliseconds.
| chan | an array of pointers to channels | |
| n | number of channels that are to be waited upon | |
| ms | time "ms" is modified in-place, if applicable |
Definition at line 1997 of file channel.c.
References ast_waitfor_nandfds().
Referenced by ast_feature_request_and_dial(), ast_udptl_bridge(), autoservice_run(), bridge_native_loop(), bridge_p2p_loop(), misdn_bridge(), monitor_dial(), rpt(), wait_for_answer(), wait_for_winner(), and zt_bridge().
01998 { 01999 return ast_waitfor_nandfds(c, n, NULL, 0, NULL, NULL, ms); 02000 }
| int ast_waitfor_n_fd | ( | int * | fds, | |
| int | n, | |||
| int * | ms, | |||
| int * | exception | |||
| ) |
Waits for input on an fd This version works on fd's only. Be careful with it.
Definition at line 1842 of file channel.c.
References ast_waitfor_nandfds().
Referenced by dundi_lookup_internal(), and dundi_precache_internal().
01843 { 01844 int winner = -1; 01845 ast_waitfor_nandfds(NULL, 0, fds, n, exception, &winner, ms); 01846 return winner; 01847 }
| struct ast_channel* ast_waitfor_nandfds | ( | struct ast_channel ** | chan, | |
| int | n, | |||
| int * | fds, | |||
| int | nfds, | |||
| int * | exception, | |||
| int * | outfd, | |||
| int * | ms | |||
| ) |
Waits for activity on a group of channels.
| chan | an array of pointers to channels | |
| n | number of channels that are to be waited upon | |
| fds | an array of fds to wait upon | |
| nfds | the number of fds to wait upon | |
| exception | exception flag | |
| outfd | fd that had activity on it | |
| ms | how long the wait was Big momma function here. Wait for activity on any of the n channels, or any of the nfds file descriptors. |
Definition at line 1850 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_set_flag, AST_SOFTHANGUP_TIMEOUT, CHECK_BLOCKING, LOG_WARNING, poll(), POLLPRI, and ast_channel::whentohangup.
Referenced by app_exec(), ast_waitfor(), ast_waitfor_n(), ast_waitfor_n_fd(), ast_waitfordigit_full(), conf_run(), find_cache(), run_agi(), and waitstream_core().
01852 { 01853 struct timeval start = { 0 , 0 }; 01854 struct pollfd *pfds; 01855 int res; 01856 long rms; 01857 int x, y, max; 01858 int sz; 01859 time_t now = 0; 01860 long whentohangup = 0, diff; 01861 struct ast_channel *winner = NULL; 01862 struct fdmap { 01863 int chan; 01864 int fdno; 01865 } *fdmap; 01866 01867 sz = n * AST_MAX_FDS + nfds; 01868 pfds = alloca(sizeof(*pfds) * sz); 01869 fdmap = alloca(sizeof(*fdmap) * sz); 01870 01871 if (outfd) 01872 *outfd = -99999; 01873 if (exception) 01874 *exception = 0; 01875 01876 /* Perform any pending masquerades */ 01877 for (x=0; x < n; x++) { 01878 ast_channel_lock(c[x]); 01879 if (c[x]->masq) { 01880 if (ast_do_masquerade(c[x])) { 01881 ast_log(LOG_WARNING, "Masquerade failed\n"); 01882 *ms = -1; 01883 ast_channel_unlock(c[x]); 01884 return NULL; 01885 } 01886 } 01887 if (c[x]->whentohangup) { 01888 if (!whentohangup) 01889 time(&now); 01890 diff = c[x]->whentohangup - now; 01891 if (diff < 1) { 01892 /* Should already be hungup */ 01893 c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT; 01894 ast_channel_unlock(c[x]); 01895 return c[x]; 01896 } 01897 if (!whentohangup || (diff < whentohangup)) 01898 whentohangup = diff; 01899 } 01900 ast_channel_unlock(c[x]); 01901 } 01902 /* Wait full interval */ 01903 rms = *ms; 01904 if (whentohangup) { 01905 rms = whentohangup * 1000; /* timeout in milliseconds */ 01906 if (*ms >= 0 && *ms < rms) /* original *ms still smaller */ 01907 rms = *ms; 01908 } 01909 /* 01910 * Build the pollfd array, putting the channels' fds first, 01911 * followed by individual fds. Order is important because 01912 * individual fd's must have priority over channel fds. 01913 */ 01914 max = 0; 01915 for (x=0; x<n; x++) { 01916 for (y=0; y<AST_MAX_FDS; y++) { 01917 fdmap[max].fdno = y; /* fd y is linked to this pfds */ 01918 fdmap[max].chan = x; /* channel x is linked to this pfds */ 01919 max += ast_add_fd(&pfds[max], c[x]->fds[y]); 01920 } 01921 CHECK_BLOCKING(c[x]); 01922 } 01923 /* Add the individual fds */ 01924 for (x=0; x<nfds; x++) { 01925 fdmap[max].chan = -1; 01926 max += ast_add_fd(&pfds[max], fds[x]); 01927 } 01928 01929 if (*ms > 0) 01930 start = ast_tvnow(); 01931 01932 if (sizeof(int) == 4) { /* XXX fix timeout > 600000 on linux x86-32 */ 01933 do { 01934 int kbrms = rms; 01935 if (kbrms > 600000) 01936 kbrms = 600000; 01937 res = poll(pfds, max, kbrms); 01938 if (!res) 01939 rms -= kbrms; 01940 } while (!res && (rms > 0)); 01941 } else { 01942 res = poll(pfds, max, rms); 01943 } 01944 for (x=0; x<n; x++) 01945 ast_clear_flag(c[x], AST_FLAG_BLOCKING); 01946 if (res < 0) { /* Simulate a timeout if we were interrupted */ 01947 if (errno != EINTR) 01948 *ms = -1; 01949 return NULL; 01950 } 01951 if (whentohangup) { /* if we have a timeout, check who expired */ 01952 time(&now); 01953 for (x=0; x<n; x++) { 01954 if (c[x]->whentohangup && now >= c[x]->whentohangup) { 01955 c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT; 01956 if (winner == NULL) 01957 winner = c[x]; 01958 } 01959 } 01960 } 01961 if (res == 0) { /* no fd ready, reset timeout and done */ 01962 *ms = 0; /* XXX use 0 since we may not have an exact timeout. */ 01963 return winner; 01964 } 01965 /* 01966 * Then check if any channel or fd has a pending event. 01967 * Remember to check channels first and fds last, as they 01968 * must have priority on setting 'winner' 01969 */ 01970 for (x = 0; x < max; x++) { 01971 res = pfds[x].revents; 01972 if (res == 0) 01973 continue; 01974 if (fdmap[x].chan >= 0) { /* this is a channel */ 01975 winner = c[fdmap[x].chan]; /* override previous winners */ 01976 if (res & POLLPRI) 01977 ast_set_flag(winner, AST_FLAG_EXCEPTION); 01978 else 01979 ast_clear_flag(winner, AST_FLAG_EXCEPTION); 01980 winner->fdno = fdmap[x].fdno; 01981 } else { /* this is an fd */ 01982 if (outfd) 01983 *outfd = pfds[x].fd; 01984 if (exception) 01985 *exception = (res & POLLPRI) ? -1 : 0; 01986 winner = NULL; 01987 } 01988 } 01989 if (*ms > 0) { 01990 *ms -= ast_tvdiff_ms(ast_tvnow(), start); 01991 if (*ms < 0) 01992 *ms = 0; 01993 } 01994 return winner; 01995 }
| 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 2013 of file channel.c.
References ast_waitfordigit_full().
Referenced by _while_exec(), advanced_options(), ast_adsi_get_cpeid(), ast_adsi_get_cpeinfo(), ast_adsi_print(), ast_adsi_read_encoded_dtmf(), ast_adsi_transmit_message_full(), ast_app_dtget(), ast_control_streamfile(), ast_record_review(), builtin_atxfer(), collect_digits(), common_exec(), cpeid_exec(), dialout(), directory_exec(), forward_message(), get_folder(), ivr_dispatch(), mgcp_ss(), my_getsigstr(), pbx_builtin_waitexten(), play_mailbox_owner(), play_record_review(), read_exec(), read_newoption(), retrydial_exec(), sendnoise(), skinny_ss(), ss_thread(), test1_client(), test1_server(), vm_execmain(), vm_forwardoptions(), vm_instructions(), vm_options(), vm_tempgreeting(), wait_a_bit(), and wait_our_turn().
02014 { 02015 return ast_waitfordigit_full(c, ms, -1, -1); 02016 }
| 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 2037 of file channel.c.
References ast_check_hangup(), AST_CONTROL_ANSWER, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_VOICE, ast_frfree(), ast_log(), ast_read(), ast_test_flag, ast_waitfor_nandfds(), f, and LOG_WARNING.
Referenced by ast_readstring_full(), ast_waitfordigit(), handle_getoption(), and handle_waitfordigit().
02038 { 02039 02040 /* Stop if we're a zombie or need a soft hangup */ 02041 if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c)) 02042 return -1; 02043 /* Wait for a digit, no more than ms milliseconds total. */ 02044 while (ms) { 02045 struct ast_channel *rchan; 02046 int outfd; 02047 02048 errno = 0; 02049 rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms); 02050 if (!rchan && outfd < 0 && ms) { 02051 if (errno == 0 || errno == EINTR) 02052 continue; 02053 ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno)); 02054 return -1; 02055 } else if (outfd > -1) { 02056 /* The FD we were watching has something waiting */ 02057 return 1; 02058 } else if (rchan) { 02059 int res; 02060 struct ast_frame *f = ast_read(c); 02061 if (!f) 02062 return -1; 02063 02064 switch(f->frametype) { 02065 case AST_FRAME_DTMF: 02066 res = f->subclass; 02067 ast_frfree(f); 02068 return res; 02069 case AST_FRAME_CONTROL: 02070 switch(f->subclass) { 02071 case AST_CONTROL_HANGUP: 02072 ast_frfree(f); 02073 return -1; 02074 case AST_CONTROL_RINGING: 02075 case AST_CONTROL_ANSWER: 02076 /* Unimportant */ 02077 break; 02078 default: 02079 ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass); 02080 break; 02081 } 02082 break; 02083 case AST_FRAME_VOICE: 02084 /* Write audio if appropriate */ 02085 if (audiofd > -1) 02086 write(audiofd, f->data, f->datalen); 02087 default: 02088 /* Ignore */ 02089 break; 02090 } 02091 ast_frfree(f); 02092 } 02093 } 02094 return 0; /* Time is up */ 02095 }
| struct ast_channel* ast_walk_channel_by_exten_locked | ( | const struct ast_channel * | chan, | |
| const char * | exten, | |||
| const char * | context | |||
| ) |
Get next channel by exten (and optionally context) and lock it.
Definition at line 1104 of file channel.c.
References channel_find_locked().
Referenced by next_channel().
01106 { 01107 return channel_find_locked(chan, NULL, 0, context, exten); 01108 }
| struct ast_channel* ast_walk_channel_by_name_prefix_locked | ( | const struct ast_channel * | chan, | |
| const char * | name, | |||
| const int | namelen | |||
| ) |
Get channel by name prefix (locks channel).
Definition at line 1091 of file channel.c.
References channel_find_locked().
Referenced by next_channel().
01093 { 01094 return channel_find_locked(chan, name, namelen, NULL, NULL); 01095 }
| 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 2673 of file channel.c.
References ast_channel::_softhangup, ast_channel_lock, ast_channel_unlock, ast_check_hangup(), ast_clear_flag, ast_deactivate_generator(), ast_do_masquerade(), AST_FLAG_BLOCKING, AST_FLAG_WHISPER, AST_FLAG_WRITE_INT, AST_FLAG_ZOMBIE, AST_FORMAT_SLINEAR, ast_frame_adjust_volume(), 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_slinear_sum(), AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree(), ast_log(), AST_MONITOR_RUNNING, ast_mutex_lock(), ast_mutex_unlock(), ast_seekstream(), ast_senddigit_begin(), ast_senddigit_end(), ast_set_write_format(), ast_slinfactory_available(), ast_slinfactory_read(), AST_SOFTHANGUP_DEV, ast_test_flag, ast_translate(), ast_translator_build_path(), ast_translator_free_path(), ast_writestream(), CHECK_BLOCKING, ast_frame::data, ast_frame::datalen, DEBUGCHAN_FLAG, f, ast_channel::fout, FRAMECOUNT_INC, ast_frame::frametype, ast_channel::generatordata, ast_channel_tech::indicate, ast_channel::insmpl, ast_frame::len, ast_channel_whisper_buffer::lock, LOG_WARNING, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, MONITOR_DELAY, ast_channel_whisper_buffer::original_format, ast_channel::outsmpl, ast_channel_whisper_buffer::path, queue_frame_to_spies(), ast_channel::rawwriteformat, SEEK_FORCECUR, ast_channel_tech::send_html, ast_channel_tech::send_text, ast_channel_whisper_buffer::sf, ast_channel::spies, SPY_WRITE, ast_channel_monitor::state, ast_frame::subclass, ast_channel::tech, ast_channel::whisper, ast_channel_tech::write, ast_channel_monitor::write_stream, ast_channel_tech::write_video, ast_channel::writeformat, and ast_channel::writetrans.
Referenced by adsi_careful_send(), agent_write(), 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(), dictate_exec(), echo_exec(), features_write(), function_ilink(), gen_generate(), handle_link_data(), jb_get_and_deliver(), linear_generator(), milliwatt_generate(), misdn_bridge(), moh_files_generator(), moh_generate(), mp3_exec(), mwanalyze_exec(), NBScat_exec(), rpt(), rpt_call(), rxfax_exec(), send_link_dtmf(), send_tone_burst(), send_waveform_to_channel(), silence_generator_generate(), spy_generate(), txfax_exec(), wait_for_answer(), and zt_bridge().
02674 { 02675 int res = -1; 02676 struct ast_frame *f = NULL; 02677 02678 /* Stop if we're a zombie or need a soft hangup */ 02679 ast_channel_lock(chan); 02680 if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) 02681 goto done; 02682 02683 /* Handle any pending masquerades */ 02684 if (chan->masq && ast_do_masquerade(chan)) { 02685 ast_log(LOG_WARNING, "Failed to perform masquerade\n"); 02686 goto done; 02687 } 02688 if (chan->masqr) { 02689 res = 0; /* XXX explain, why 0 ? */ 02690 goto done; 02691 } 02692 if (chan->generatordata) { 02693 if (ast_test_flag(chan, AST_FLAG_WRITE_INT)) 02694 ast_deactivate_generator(chan); 02695 else { 02696 res = 0; /* XXX explain, why 0 ? */ 02697 goto done; 02698 } 02699 } 02700 /* High bit prints debugging */ 02701 if (chan->fout & DEBUGCHAN_FLAG) 02702 ast_frame_dump(chan->name, fr, ">>"); 02703 CHECK_BLOCKING(chan); 02704 switch(fr->frametype) { 02705 case AST_FRAME_CONTROL: 02706 res = (chan->tech->indicate == NULL) ? 0 : 02707 chan->tech->indicate(chan, fr->subclass, fr->data, fr->datalen); 02708 break; 02709 case AST_FRAME_DTMF_BEGIN: 02710 ast_clear_flag(chan, AST_FLAG_BLOCKING); 02711 ast_channel_unlock(chan); 02712 res = ast_senddigit_begin(chan, fr->subclass); 02713 ast_channel_lock(chan); 02714 CHECK_BLOCKING(chan); 02715 break; 02716 case AST_FRAME_DTMF_END: 02717 ast_clear_flag(chan, AST_FLAG_BLOCKING); 02718 ast_channel_unlock(chan); 02719 res = ast_senddigit_end(chan, fr->subclass, fr->len); 02720 ast_channel_lock(chan); 02721 CHECK_BLOCKING(chan); 02722 break; 02723 case AST_FRAME_TEXT: 02724 res = (chan->tech->send_text == NULL) ? 0 : 02725 chan->tech->send_text(chan, (char *) fr->data); 02726 break; 02727 case AST_FRAME_HTML: 02728 res = (chan->tech->send_html == NULL) ? 0 : 02729 chan->tech->send_html(chan, fr->subclass, (char *) fr->data, fr->datalen); 02730 break; 02731 case AST_FRAME_VIDEO: 02732 /* XXX Handle translation of video codecs one day XXX */ 02733 res = (chan->tech->write_video == NULL) ? 0 : 02734 chan->tech->write_video(chan, fr); 02735 break; 02736 case AST_FRAME_MODEM: 02737 res = (chan->tech->write == NULL) ? 0 : 02738 chan->tech->write(chan, fr); 02739 break; 02740 case AST_FRAME_VOICE: 02741 if (chan->tech->write == NULL) 02742 break; /*! \todo XXX should return 0 maybe ? */ 02743 02744 /* If someone is whispering on this channel then we must ensure that we are always getting signed linear frames */ 02745 if (ast_test_flag(chan, AST_FLAG_WHISPER)) { 02746 if (fr->subclass == AST_FORMAT_SLINEAR) 02747 f = fr; 02748 else { 02749 ast_mutex_lock(&chan->whisper->lock); 02750 if (chan->writeformat != AST_FORMAT_SLINEAR) { 02751 /* Rebuild the translation path and set our write format back to signed linear */ 02752 chan->whisper->original_format = chan->writeformat; 02753 ast_set_write_format(chan, AST_FORMAT_SLINEAR); 02754 if (chan->whisper->path) 02755 ast_translator_free_path(chan->whisper->path); 02756 chan->whisper->path = ast_translator_build_path(AST_FORMAT_SLINEAR, chan->whisper->original_format); 02757 } 02758 /* Translate frame using the above translation path */ 02759 f = (chan->whisper->path) ? ast_translate(chan->whisper->path, fr, 0) : fr; 02760 ast_mutex_unlock(&chan->whisper->lock); 02761 } 02762 } else { 02763 /* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */ 02764 if (fr->subclass == chan->rawwriteformat) 02765 f = fr; 02766 else 02767 f = (chan->writetrans) ? ast_translate(chan->writetrans, fr, 0) : fr; 02768 } 02769 02770 /* If we have no frame of audio, then we have to bail out */ 02771 if (f == NULL) { 02772 res = 0; 02773 break; 02774 } 02775 02776 /* If spies are on the channel then queue the frame out to them */ 02777 if (chan->spies) 02778 queue_frame_to_spies(chan, f, SPY_WRITE); 02779 02780 /* If Monitor is running on this channel, then we have to write frames out there too */ 02781 if (chan->monitor && chan->monitor->write_stream) { 02782 /* XXX must explain this code */ 02783 #ifndef MONITOR_CONSTANT_DELAY 02784 int jump = chan->insmpl - chan->outsmpl - 4 * f->samples; 02785 if (jump >= 0) { 02786 jump = chan->insmpl - chan->outsmpl; 02787 if (ast_seekstream(chan->monitor->write_stream, jump, SEEK_FORCECUR) == -1) 02788 ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n"); 02789 chan->outsmpl += jump + f->samples; 02790 } else 02791 chan->outsmpl += f->samples; 02792 #else 02793 int jump = chan->insmpl - chan->outsmpl; 02794 if (jump - MONITOR_DELAY >= 0) { 02795 if (ast_seekstream(chan->monitor->write_stream, jump - f->samples, SEEK_FORCECUR) == -1) 02796 ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n"); 02797 chan->outsmpl += jump; 02798 } else 02799 chan->outsmpl += f->samples; 02800 #endif 02801 if (chan->monitor->state == AST_MONITOR_RUNNING) { 02802 if (ast_writestream(chan->monitor->write_stream, f) < 0) 02803 ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n"); 02804 } 02805 } 02806 02807 /* Finally the good part! Write this out to the channel */ 02808 if (ast_test_flag(chan, AST_FLAG_WHISPER)) { 02809 /* frame is assumed to be in SLINEAR, since that is 02810 required for whisper mode */ 02811 ast_frame_adjust_volume(f, -2); 02812 if (ast_slinfactory_available(&chan->whisper->sf) >= f->samples) { 02813 short buf[f->samples]; 02814 struct ast_frame whisper = { 02815 .frametype = AST_FRAME_VOICE, 02816 .subclass = AST_FORMAT_SLINEAR, 02817 .data = buf, 02818 .datalen = sizeof(buf), 02819 .samples = f->samples, 02820 }; 02821 02822 ast_mutex_lock(&chan->whisper->lock); 02823 if (ast_slinfactory_read(&chan->whisper->sf, buf, f->samples)) 02824 ast_frame_slinear_sum(f, &whisper); 02825 ast_mutex_unlock(&chan->whisper->lock); 02826 } 02827 /* and now put it through the regular translator */ 02828 f = (chan->writetrans) ? ast_translate(chan->writetrans, f, 0) : f; 02829 } 02830 if (f) 02831 res = chan->tech->write(chan, f); 02832 else 02833 res = 0; 02834 break; 02835 case AST_FRAME_NULL: 02836 case AST_FRAME_IAX: 02837 /* Ignore these */ 02838 res = 0; 02839 break; 02840 default: 02841 /* At this point, fr is the incoming frame and f is NULL. Channels do 02842 * not expect to get NULL as a frame pointer and will segfault. Hence, 02843 * we output the original frame passed in. */ 02844 res = chan->tech->write(chan, fr); 02845 break; 02846 } 02847 02848 if (f && f != fr) 02849 ast_frfree(f); 02850 ast_clear_flag(chan, AST_FLAG_BLOCKING); 02851 /* Consider a write failure to force a soft hangup */ 02852 if (res < 0) 02853 chan->_softhangup |= AST_SOFTHANGUP_DEV; 02854 else { 02855 chan->fout = FRAMECOUNT_INC(chan->fout); 02856 } 02857 done: 02858 ast_channel_unlock(chan); 02859 return res; 02860 }
| 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 2662 of file channel.c.
References ast_write(), ast_channel::tech, and ast_channel_tech::write_video.
02663 { 02664 int res; 02665 if (!chan->tech->write_video) 02666 return 0; 02667 res = ast_write(chan, fr); 02668 if (!res) 02669 res = 1; 02670 return res; 02671 }
| static void bridge_playfile | ( | struct ast_channel * | chan, | |
| struct ast_channel * | peer, | |||
| const char * | sound, | |||
| int | remain | |||
| ) | [static] |
Definition at line 3757 of file channel.c.
References ast_autoservice_start(), ast_autoservice_stop(), AST_DIGIT_ANY, ast_say_number(), and ast_stream_and_wait().
Referenced by ast_channel_bridge().
03758 { 03759 int min = 0, sec = 0, check; 03760 03761 check = ast_autoservice_start(peer); 03762 if (check) 03763 return; 03764 03765 if (remain > 0) { 03766 if (remain / 60 > 1) { 03767 min = remain / 60; 03768 sec = remain % 60; 03769 } else { 03770 sec = remain; 03771 } 03772 } 03773 03774 if (!strcmp(sound,"timeleft")) { /* Queue support */ 03775 ast_stream_and_wait(chan, "vm-youhave", chan->language, ""); 03776 if (min) { 03777 ast_say_number(chan, min, AST_DIGIT_ANY, chan->language, NULL); 03778 ast_stream_and_wait(chan, "queue-minutes", chan->language, ""); 03779 } 03780 if (sec) { 03781 ast_say_number(chan, sec, AST_DIGIT_ANY, chan->language, NULL); 03782 ast_stream_and_wait(chan, "queue-seconds", chan->language, ""); 03783 } 03784 } else { 03785 ast_stream_and_wait(chan, sound, chan->language, ""); 03786 } 03787 03788 ast_autoservice_stop(peer); 03789 }
| static struct ast_channel* channel_find_locked | ( | const struct ast_channel * | prev, | |
| const char * | name, | |||
| const int | namelen, | |||
| const char * | context, | |||
| const char * | exten | |||
| ) | [static] |
Helper function to find channels.
It supports these modes:
prev != NULL : get channel next in list after prev name != NULL : get channel with matching name name != NULL && namelen != 0 : get channel whose name starts with prefix exten != NULL : get channel whose exten or macroexten matches context != NULL && exten != NULL : get channel whose context or macrocontext
It returns with the channel's lock held. If getting the individual lock fails, unlock and retry quickly up to 10 times, then give up.
XXX also note that accessing fields (e.g. c->name in ast_log()) can only be done with the lock held or someone could delete the object while we work on it. This causes some ugliness in the code. Note that removing the first ast_log() may be harmful, as it would shorten the retry period and possibly cause failures. We should definitely go for a better scheme that is deadlock-free.
Definition at line 1013 of file channel.c.
References ast_channel_trylock, AST_LIST_LOCK, AST_LIST_NEXT, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_channel::context, ast_channel::exten, LOG_DEBUG, ast_channel::macrocontext, ast_channel::macroexten, and option_debug.
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().
01016 { 01017 const char *msg = prev ? "deadlock" : "initial deadlock"; 01018 int retries; 01019 struct ast_channel *c; 01020 01021 for (retries = 0; retries < 10; retries++) { 01022 int done; 01023 AST_LIST_LOCK(&channels); 01024 AST_LIST_TRAVERSE(&channels, c, chan_list) { 01025 if (prev) { /* look for next item */ 01026 if (c != prev) /* not this one */ 01027 continue; 01028 /* found, prepare to return c->next */ 01029 if ((c = AST_LIST_NEXT(c, chan_list)) == NULL) break; 01030 /* If prev was the last item on the channel list, then we just 01031 * want to return NULL, instead of trying to deref NULL in the 01032 * next section. 01033 */ 01034 } 01035 if (name) { /* want match by name */ 01036 if ((!namelen && strcasecmp(c->name, name)) || 01037 (namelen && strncasecmp(c->name, name, namelen))) 01038 continue; /* name match failed */ 01039 } else if (exten) { 01040 if (context && strcasecmp(c->context, context) && 01041 strcasecmp(c->macrocontext, context)) 01042 continue; /* context match failed */ 01043 if (strcasecmp(c->exten, exten) && 01044 strcasecmp(c->macroexten, exten)) 01045 continue; /* exten match failed */ 01046 } 01047 /* if we get here, c points to the desired record */ 01048 break; 01049 } 01050 /* exit if chan not found or mutex acquired successfully */ 01051 /* this is slightly unsafe, as we _should_ hold the lock to access c->name */ 01052 done = c == NULL || ast_channel_trylock(c) == 0; 01053 if (!done) 01054 if (option_debug) 01055 ast_log(LOG_DEBUG, "Avoiding %s for channel '%p'\n", msg, c); 01056 AST_LIST_UNLOCK(&channels); 01057 if (done) 01058 return c; 01059 usleep(1); /* give other threads a chance before retrying */ 01060 } 01061 /* 01062 * c is surely not null, but we don't have the lock so cannot 01063 * access c->name 01064 */ 01065 if (option_debug) 01066 ast_log(LOG_DEBUG, "Failure, could not lock '%p' after %d retries!\n", 01067 c, retries); 01068 01069 return NULL; 01070 }
| 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 4680 of file channel.c.
References CHANNEL_CLI_RELOAD, CHANNEL_MODULE_LOAD, and CHANNEL_MODULE_RELOAD.
04681 { 04682 switch (reason) { 04683 case CHANNEL_MODULE_LOAD: 04684 return "LOAD (Channel module load)"; 04685 04686 case CHANNEL_MODULE_RELOAD: 04687 return "RELOAD (Channel module reload)"; 04688 04689 case CHANNEL_CLI_RELOAD: 04690 return "CLIRELOAD (Channel module reload by CLI command)"; 04691 04692 default: 04693 return "MANAGERRELOAD (Channel module reload by manager)"; 04694 } 04695 };
| static void clone_variables | ( | struct ast_channel * | original, | |
| struct ast_channel * | clone | |||
| ) | [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 3390 of file channel.c.
References AST_LIST_APPEND_LIST, AST_LIST_FIRST, and ast_channel::varshead.
03391 { 03392 /* Append variables from clone channel into original channel */ 03393 /* XXX Is this always correct? We have to in order to keep MACROS working XXX */ 03394 if (AST_LIST_FIRST(&clone->varshead)) 03395 AST_LIST_APPEND_LIST(&original->varshead, &clone->varshead, entries); 03396 }
| static char* complete_channeltypes | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Definition at line 351 of file channel.c.
References AST_LIST_TRAVERSE, strdup, chanlist::tech, and ast_channel_tech::type.
00352 { 00353 struct chanlist *cl; 00354 int which = 0; 00355 int wordlen; 00356 char *ret = NULL; 00357 00358 if (pos != 3) 00359 return NULL; 00360 00361 wordlen = strlen(word); 00362 00363 AST_LIST_TRAVERSE(&backends, cl, list) { 00364 if (!strncasecmp(word, cl->tech->type, wordlen) && ++which > state) { 00365 ret = strdup(cl->tech->type); 00366 break; 00367 } 00368 } 00369 00370 return ret; 00371 }
| static char* complete_channeltypes_deprecated | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Definition at line 329 of file channel.c.
References AST_LIST_TRAVERSE, strdup, chanlist::tech, and ast_channel_tech::type.
00330 { 00331 struct chanlist *cl; 00332 int which = 0; 00333 int wordlen; 00334 char *ret = NULL; 00335 00336 if (pos != 2) 00337 return NULL; 00338 00339 wordlen = strlen(word); 00340 00341 AST_LIST_TRAVERSE(&backends, cl, list) { 00342 if (!strncasecmp(word, cl->tech->type, wordlen) && ++which > state) { 00343 ret = strdup(cl->tech->type); 00344 break; 00345 } 00346 } 00347 00348 return ret; 00349 }
| static void copy_data_from_queue | ( | struct ast_channel_spy_queue * | queue, | |
| short * | buf, | |||
| unsigned int | samples | |||
| ) | [static] |
Definition at line 4478 of file channel.c.
References ast_codec_get_len(), ast_frfree(), AST_LIST_FIRST, AST_LIST_REMOVE_HEAD, ast_log(), f, ast_channel_spy_queue::format, LOG_ERROR, and ast_channel_spy_queue::samples.
Referenced by ast_channel_spy_read_frame().
04479 { 04480 struct ast_frame *f; 04481 int tocopy; 04482 int bytestocopy; 04483 04484 while (samples) { 04485 if (!(f = AST_LIST_FIRST(&queue->list))) { 04486 ast_log(LOG_ERROR, "Ran out of frames before buffer filled!\n"); 04487 break; 04488 } 04489 04490 tocopy = (f->samples > samples) ? samples : f->samples; 04491 bytestocopy = ast_codec_get_len(queue->format, tocopy); 04492 memcpy(buf, f->data, bytestocopy); 04493 samples -= tocopy; 04494 buf += tocopy; 04495 f->samples -= tocopy; 04496 f->data += bytestocopy; 04497 f->datalen -= bytestocopy; 04498 f->offset += bytestocopy; 04499 queue->samples -= tocopy; 04500 04501 if (!f->samples) 04502 ast_frfree(AST_LIST_REMOVE_HEAD(&queue->list, frame_list)); 04503 } 04504 }
| static void detach_spies | ( | struct ast_channel * | chan | ) | [static] |
Definition at line 1491 of file channel.c.
References AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_channel_spy::chan, ast_channel::spies, spy_cleanup(), and spy_detach().
Referenced by ast_hangup().
01492 { 01493 struct ast_channel_spy *spy = NULL; 01494 01495 if (!chan->spies) 01496 return; 01497 01498 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->spies->list, spy, list) { 01499 AST_LIST_REMOVE_CURRENT(&chan->spies->list, list); 01500 spy_detach(spy, chan); 01501 } 01502 AST_LIST_TRAVERSE_SAFE_END 01503 01504 spy_cleanup(chan); 01505 }
| static void free_cid | ( | struct ast_callerid * | cid | ) | [static] |
Definition at line 1137 of file channel.c.
References ast_callerid::cid_ani, ast_callerid::cid_dnid, ast_callerid::cid_name, ast_callerid::cid_num, ast_callerid::cid_rdnis, and free.
Referenced by ast_channel_free().
01138 { 01139 if (cid->cid_dnid) 01140 free(cid->cid_dnid); 01141 if (cid->cid_num) 01142 free(cid->cid_num); 01143 if (cid->cid_name) 01144 free(cid->cid_name); 01145 if (cid->cid_ani) 01146 free(cid->cid_ani); 01147 if (cid->cid_rdnis) 01148 free(cid->cid_rdnis); 01149 }
| static void free_translation | ( | struct ast_channel * | clone | ) | [static] |
Definition at line 1651 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().
01652 { 01653 if (clone->writetrans) 01654 ast_translator_free_path(clone->writetrans); 01655 if (clone->readtrans) 01656 ast_translator_free_path(clone->readtrans); 01657 clone->writetrans = NULL; 01658 clone->readtrans = NULL; 01659 clone->rawwriteformat = clone->nativeformats; 01660 clone->rawreadformat = clone->nativeformats; 01661 }
| static int generator_force | ( | void * | data | ) | [static] |
Definition at line 1794 of file channel.c.
References ast_deactivate_generator(), ast_log(), ast_generator::generate, ast_channel::generator, ast_channel::generatordata, LOG_DEBUG, and option_debug.
Referenced by __ast_read(), and ast_activate_generator().
01795 { 01796 /* Called if generator doesn't have data */ 01797 void *tmp; 01798 int res; 01799 int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples); 01800 struct ast_channel *chan = data; 01801 tmp = chan->generatordata; 01802 chan->generatordata = NULL; 01803 generate = chan->generator->generate; 01804 res = generate(chan, tmp, 0, 160); 01805 chan->generatordata = tmp; 01806 if (res) { 01807 if (option_debug) 01808 ast_log(LOG_DEBUG, "Auto-deactivating generator\n"); 01809 ast_deactivate_generator(chan); 01810 } 01811 return 0; 01812 }
| static void queue_frame_to_spies | ( | struct ast_channel * | chan, | |
| struct ast_frame * | f, | |||
| enum spy_direction | dir | |||
| ) | [static] |
Definition at line 1538 of file channel.c.
References ast_clear_flag, ast_cond_signal(), AST_FORMAT_SLINEAR, ast_frdup(), ast_frfree(), ast_getformatname(), AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_set_flag, ast_test_flag, ast_translate(), ast_translator_build_path(), ast_translator_free_path(), CHANSPY_TRIGGER_FLUSH, CHANSPY_TRIGGER_MODE, CHANSPY_TRIGGER_NONE, CHANSPY_TRIGGER_READ, CHANSPY_TRIGGER_WRITE, f, ast_channel_spy_queue::format, channel_spy_trans::last_format, ast_channel_spy::lock, LOG_DEBUG, LOG_ERROR, LOG_WARNING, option_debug, channel_spy_trans::path, ast_channel_spy::read_queue, ast_channel_spy_list::read_translator, ast_frame::samples, ast_channel_spy_queue::samples, ast_channel::spies, SPY_QUEUE_SAMPLE_LIMIT, SPY_READ, SPY_WRITE, ast_channel_spy::trigger, ast_channel_spy::type, ast_channel_spy::write_queue, and ast_channel_spy_list::write_translator.
Referenced by __ast_read(), and ast_write().
01539 { 01540 struct ast_frame *translated_frame = NULL; 01541 struct ast_channel_spy *spy; 01542 struct channel_spy_trans *trans; 01543 01544 trans = (dir == SPY_READ) ? &chan->spies->read_translator : &chan->spies->write_translator; 01545 01546 AST_LIST_TRAVERSE(&chan->spies->list, spy, list) { 01547 struct ast_channel_spy_queue *queue; 01548 struct ast_frame *duped_fr; 01549 01550 ast_mutex_lock(&spy->lock); 01551 01552 queue = (dir == SPY_READ) ? &spy->read_queue : &spy->write_queue; 01553 01554 if ((queue->format == AST_FORMAT_SLINEAR) && (f->subclass != AST_FORMAT_SLINEAR)) { 01555 if (!translated_frame) { 01556 if (trans->path && (trans->last_format != f->subclass)) { 01557 ast_translator_free_path(trans->path); 01558 trans->path = NULL; 01559 } 01560 if (!trans->path) { 01561 if (option_debug) 01562 ast_log(LOG_DEBUG, "Building translator from %s to SLINEAR for spies on channel %s\n", 01563 ast_getformatname(f->subclass), chan->name); 01564 if ((trans->path = ast_translator_build_path(AST_FORMAT_SLINEAR, f->subclass)) == NULL) { 01565 ast_log(LOG_WARNING, "Cannot build a path from %s to %s\n", 01566 ast_getformatname(f->subclass), ast_getformatname(AST_FORMAT_SLINEAR)); 01567 ast_mutex_unlock(&spy->lock); 01568 continue; 01569 } else { 01570 trans->last_format = f->subclass; 01571 } 01572 } 01573 if (!(translated_frame = ast_translate(trans->path, f, 0))) { 01574 ast_log(LOG_ERROR, "Translation to %s failed, dropping frame for spies\n", 01575 ast_getformatname(AST_FORMAT_SLINEAR)); 01576 ast_mutex_unlock(&spy->lock); 01577 break; 01578 } 01579 } 01580 duped_fr = ast_frdup(translated_frame); 01581 } else if (f->subclass != queue->format) { 01582 ast_log(LOG_WARNING, "Spy '%s' on channel '%s' wants format '%s', but frame is '%s', dropping\n", 01583 spy->type, chan->name, 01584 ast_getformatname(queue->format), ast_getformatname(f->subclass)); 01585 ast_mutex_unlock(&spy->lock); 01586 continue; 01587 } else 01588 duped_fr = ast_frdup(f); 01589 01590 AST_LIST_INSERT_TAIL(&queue->list, duped_fr, frame_list); 01591 01592 queue->samples += f->samples; 01593 01594 if (queue->samples > SPY_QUEUE_SAMPLE_LIMIT) { 01595 if (ast_test_flag(spy, CHANSPY_TRIGGER_MODE) != CHANSPY_TRIGGER_NONE) { 01596 switch (ast_test_flag(spy, CHANSPY_TRIGGER_MODE)) { 01597 case CHANSPY_TRIGGER_READ: 01598 if (dir == SPY_WRITE) { 01599 ast_set_flag(spy, CHANSPY_TRIGGER_WRITE); 01600 ast_clear_flag(spy, CHANSPY_TRIGGER_READ); 01601 if (option_debug) 01602 ast_log(LOG_DEBUG, "Switching spy '%s' on '%s' to write-trigger mode\n", 01603 spy->type, chan->name); 01604 } 01605 break; 01606 case CHANSPY_TRIGGER_WRITE: 01607 if (dir == SPY_READ) { 01608 ast_set_flag(spy, CHANSPY_TRIGGER_READ); 01609 ast_clear_flag(spy, CHANSPY_TRIGGER_WRITE); 01610 if (option_debug) 01611 ast_log(LOG_DEBUG, "Switching spy '%s' on '%s' to read-trigger mode\n", 01612 spy->type, chan->name); 01613 } 01614 break; 01615 } 01616 if (option_debug) 01617 ast_log(LOG_DEBUG, "Triggering queue flush for spy '%s' on '%s'\n", 01618 spy->type, chan->name); 01619 ast_set_flag(spy, CHANSPY_TRIGGER_FLUSH); 01620 ast_cond_signal(&spy->trigger); 01621 } else { 01622 if (option_debug) 01623 ast_log(LOG_DEBUG, "Spy '%s' on channel '%s' %s queue too long, dropping frames\n", 01624 spy->type, chan->name, (dir == SPY_READ) ? "read" : "write"); 01625 while (queue->samples > SPY_QUEUE_SAMPLE_LIMIT) { 01626 struct ast_frame *drop = AST_LIST_REMOVE_HEAD(&queue->list, frame_list); 01627 queue->samples -= drop->samples; 01628 ast_frfree(drop); 01629 } 01630 } 01631 } else { 01632 switch (ast_test_flag(spy, CHANSPY_TRIGGER_MODE)) { 01633 case CHANSPY_TRIGGER_READ: 01634 if (dir == SPY_READ) 01635 ast_cond_signal(&spy->trigger); 01636 break; 01637 case CHANSPY_TRIGGER_WRITE: 01638 if (dir == SPY_WRITE) 01639 ast_cond_signal(&spy->trigger); 01640 break; 01641 } 01642 } 01643 01644 ast_mutex_unlock(&spy->lock); 01645 } 01646 01647 if (translated_frame) 01648 ast_frfree(translated_frame); 01649 }
| 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 2862 of file channel.c.
References ast_channel_lock, ast_channel_unlock, AST_FORMAT_AUDIO_MASK, ast_getformatname(), ast_log(), ast_translator_best_choice(), ast_translator_build_path(), ast_translator_free_path(), LOG_DEBUG, LOG_WARNING, ast_channel::nativeformats, and option_debug.
Referenced by ast_set_read_format(), and ast_set_write_format().
02864 { 02865 int native; 02866 int res; 02867 02868 /* Make sure we only consider audio */ 02869 fmt &= AST_FORMAT_AUDIO_MASK; 02870 02871 native = chan->nativeformats; 02872 /* Find a translation path from the native format to one of the desired formats */ 02873 if (!direction) 02874 /* reading */ 02875 res = ast_translator_best_choice(&fmt, &native); 02876 else 02877 /* writing */ 02878 res = ast_translator_best_choice(&native, &fmt); 02879 02880 if (res < 0) { 02881 ast_log(LOG_WARNING, "Unable to find a codec translation path from %s to %s\n", 02882 ast_getformatname(native), ast_getformatname(fmt)); 02883 return -1; 02884 } 02885 02886 /* Now we have a good choice for both. */ 02887 ast_channel_lock(chan); 02888 02889 if ((*rawformat == native) && (*format == fmt) && ((*rawformat == *format) || (*trans))) { 02890 /* the channel is already in these formats, so nothing to do */ 02891 ast_channel_unlock(chan); 02892 return 0; 02893 } 02894 02895 *rawformat = native; 02896 /* User perspective is fmt */ 02897 *format = fmt; 02898 /* Free any read translation we have right now */ 02899 if (*trans) 02900 ast_translator_free_path(*trans); 02901 /* Build a translation path from the raw format to the desired format */ 02902 if (!direction) 02903 /* reading */ 02904 *trans = ast_translator_build_path(*format, *rawformat); 02905 else 02906 /* writing */ 02907 *trans = ast_translator_build_path(*rawformat, *format); 02908 ast_channel_unlock(chan); 02909 if (option_debug) 02910 ast_log(LOG_DEBUG, "Set channel %s to %s format %s\n", chan->name, 02911 direction ? "write" : "read", ast_getformatname(fmt)); 02912 return 0; 02913 }
| static int show_channeltype | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 276 of file channel.c.
References ast_cli(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_channel_tech::capabilities, ast_channel_tech::devicestate, ast_channel_tech::indicate, LOG_WARNING, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, 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, and ast_channel_tech::type.
00277 { 00278 struct chanlist *cl = NULL; 00279 00280 if (argc != 4) 00281 return RESULT_SHOWUSAGE; 00282 00283 if (AST_LIST_LOCK(&channels)) { 00284 ast_log(LOG_WARNING, "Unable to lock channel list\n"); 00285 return RESULT_FAILURE; 00286 } 00287 00288 AST_LIST_TRAVERSE(&backends, cl, list) { 00289 if (!strncasecmp(cl->tech->type, argv[3], strlen(cl->tech->type))) { 00290 break; 00291 } 00292 } 00293 00294 00295 if (!cl) { 00296 ast_cli(fd, "\n%s is not a registered channel driver.\n", argv[3]); 00297 AST_LIST_UNLOCK(&channels); 00298 return RESULT_FAILURE; 00299 } 00300 00301 ast_cli(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_LIST_UNLOCK(&channels); 00326 return RESULT_SUCCESS; 00327 }
| static int show_channeltype_deprecated | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 223 of file channel.c.
References ast_cli(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_channel_tech::capabilities, ast_channel_tech::devicestate, ast_channel_tech::indicate, LOG_WARNING, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, 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, and ast_channel_tech::type.
00224 { 00225 struct chanlist *cl = NULL; 00226 00227 if (argc != 3) 00228 return RESULT_SHOWUSAGE; 00229 00230 if (AST_LIST_LOCK(&channels)) { 00231 ast_log(LOG_WARNING, "Unable to lock channel list\n"); 00232 return RESULT_FAILURE; 00233 } 00234 00235 AST_LIST_TRAVERSE(&backends, cl, list) { 00236 if (!strncasecmp(cl->tech->type, argv[2], strlen(cl->tech->type))) { 00237 break; 00238 } 00239 } 00240 00241 00242 if (!cl) { 00243 ast_cli(fd, "\n%s is not a registered channel driver.\n", argv[2]); 00244 AST_LIST_UNLOCK(&channels); 00245 return RESULT_FAILURE; 00246 } 00247 00248 ast_cli(fd, 00249 "-- Info about channel driver: %s --\n" 00250 " Device State: %s\n" 00251 " Indication: %s\n" 00252 " Transfer : %s\n" 00253 " Capabilities: %d\n" 00254 " Digit Begin: %s\n" 00255 " Digit End: %s\n" 00256 " Send HTML : %s\n" 00257 " Image Support: %s\n" 00258 " Text Support: %s\n", 00259 cl->tech->type, 00260 (cl->tech->devicestate) ? "yes" : "no", 00261 (cl->tech->indicate) ? "yes" : "no", 00262 (cl->tech->transfer) ? "yes" : "no", 00263 (cl->tech->capabilities) ? cl->tech->capabilities : -1, 00264 (cl->tech->send_digit_begin) ? "yes" : "no", 00265 (cl->tech->send_digit_end) ? "yes" : "no", 00266 (cl->tech->send_html) ? "yes" : "no", 00267 (cl->tech->send_image) ? "yes" : "no", 00268 (cl->tech->send_text) ? "yes" : "no" 00269 00270 ); 00271 00272 AST_LIST_UNLOCK(&channels); 00273 return RESULT_SUCCESS; 00274 }
| static int show_channeltypes | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 196 of file channel.c.
References ast_cli(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_channel_tech::description, ast_channel_tech::devicestate, FORMAT, ast_channel_tech::indicate, LOG_WARNING, RESULT_SUCCESS, chanlist::tech, ast_channel_tech::transfer, and ast_channel_tech::type.
00197 { 00198 #define FORMAT "%-10.10s %-40.40s %-12.12s %-12.12s %-12.12s\n" 00199 struct chanlist *cl; 00200 int count_chan = 0; 00201 00202 ast_cli(fd, FORMAT, "Type", "Description", "Devicestate", "Indications", "Transfer"); 00203 ast_cli(fd, FORMAT, "----------", "-----------", "-----------", "-----------", "--------"); 00204 if (AST_LIST_LOCK(&channels)) { 00205 ast_log(LOG_WARNING, "Unable to lock channel list\n"); 00206 return -1; 00207 } 00208 AST_LIST_TRAVERSE(&backends, cl, list) { 00209 ast_cli(fd, FORMAT, cl->tech->type, cl->tech->description, 00210 (cl->tech->devicestate) ? "yes" : "no", 00211 (cl->tech->indicate) ? "yes" : "no", 00212 (cl->tech->transfer) ? "yes" : "no"); 00213 count_chan++; 00214 } 00215 AST_LIST_UNLOCK(&channels); 00216 ast_cli(fd, "----------\n%d channel drivers registered.\n", count_chan); 00217 return RESULT_SUCCESS; 00218 00219 #undef FORMAT 00220 00221 }
| 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 4612 of file channel.c.
References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_write(), and ast_frame::frametype.
04613 { 04614 short buf[samples]; 04615 struct ast_frame frame = { 04616 .frametype = AST_FRAME_VOICE, 04617 .subclass = AST_FORMAT_SLINEAR, 04618 .data = buf, 04619 .samples = samples, 04620 .datalen = sizeof(buf), 04621 }; 04622 memset(buf, 0, sizeof(buf)); 04623 if (ast_write(chan, &frame)) 04624 return -1; 04625 return 0; 04626 }
| static void silence_generator_release | ( | struct ast_channel * | chan, | |
| void * | data | |||
| ) | [static] |
| static void spy_cleanup | ( | struct ast_channel * | chan | ) | [static] |
Definition at line 1386 of file channel.c.
References AST_LIST_EMPTY, ast_translator_free_path(), free, channel_spy_trans::path, ast_channel_spy_list::read_translator, ast_channel::spies, and ast_channel_spy_list::write_translator.
Referenced by ast_channel_spy_remove(), ast_channel_spy_stop_by_type(), and detach_spies().
01387 { 01388 if (!AST_LIST_EMPTY(&chan->spies->list)) 01389 return; 01390 if (chan->spies->read_translator.path) 01391 ast_translator_free_path(chan->spies->read_translator.path); 01392 if (chan->spies->write_translator.path) 01393 ast_translator_free_path(chan->spies->write_translator.path); 01394 free(chan->spies); 01395 chan->spies = NULL; 01396 return; 01397 }
| static void spy_detach | ( | struct ast_channel_spy * | spy, | |
| struct ast_channel * | chan | |||
| ) | [static] |
Definition at line 1400 of file channel.c.
References ast_cond_signal(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_test_flag, ast_channel_spy::chan, CHANSPY_DONE, CHANSPY_STOP, CHANSPY_TRIGGER_MODE, CHANSPY_TRIGGER_NONE, ast_channel_spy::lock, LOG_DEBUG, option_debug, ast_channel_spy::status, ast_channel_spy::trigger, and ast_channel_spy::type.
Referenced by ast_channel_spy_remove(), ast_channel_spy_stop_by_type(), and detach_spies().
01401 { 01402 ast_mutex_lock(&spy->lock); 01403 01404 /* We only need to poke them if they aren't already done */ 01405 if (spy->status != CHANSPY_DONE) { 01406 /* Indicate to the spy to stop */ 01407 spy->status = CHANSPY_STOP; 01408 spy->chan = NULL; 01409 /* Poke the spy if needed */ 01410 if (ast_test_flag(spy, CHANSPY_TRIGGER_MODE) != CHANSPY_TRIGGER_NONE) 01411 ast_cond_signal(&spy->trigger); 01412 } 01413 01414 /* Print it out while we still have a lock so the structure can't go away (if signalled above) */ 01415 if (option_debug) 01416 ast_log(LOG_DEBUG, "Spy %s removed from channel %s\n", spy->type, chan->name); 01417 01418 ast_mutex_unlock(&spy->lock); 01419 01420 return; 01421 }
| static void* tonepair_alloc | ( | struct ast_channel * | chan, | |
| void * | params | |||
| ) | [static] |
Definition at line 4245 of file channel.c.
References ast_calloc, AST_FLAG_WRITE_INT, AST_FORMAT_SLINEAR, ast_log(), ast_set_flag, ast_set_write_format(), tonepair_def::duration, tonepair_def::freq1, tonepair_def::freq2, LOG_WARNING, tonepair_release(), tonepair_def::vol, and ast_channel::writeformat.
04246 { 04247 struct tonepair_state *ts; 04248 struct tonepair_def *td = params; 04249 04250 if (!(ts = ast_calloc(1, sizeof(*ts)))) 04251 return NULL; 04252 ts->origwfmt = chan->writeformat; 04253 if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) { 04254 ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name); 04255 tonepair_release(NULL, ts); 04256 ts = NULL; 04257 } else { 04258 ts->fac1 = 2.0 * cos(2.0 * M_PI * (td->freq1 / 8000.0)) * 32768.0; 04259 ts->v1_1 = 0; 04260 ts->v2_1 = sin(-4.0 * M_PI * (td->freq1 / 8000.0)) * td->vol; 04261 ts->v3_1 = sin(-2.0 * M_PI * (td->freq1 / 8000.0)) * td->vol; 04262 ts->v2_1 = 0; 04263 ts->fac2 = 2.0 * cos(2.0 * M_PI * (td->freq2 / 8000.0)) * 32768.0; 04264 ts->v2_2 = sin(-4.0 * M_PI * (td->freq2 / 8000.0)) * td->vol; 04265 ts->v3_2 = sin(-2.0 * M_PI * (td->freq2 / 8000.0)) * td->vol; 04266 ts->duration = td->duration; 04267 ts->modulate = 0; 04268 } 04269 /* Let interrupts interrupt :) */ 04270 ast_set_flag(chan, AST_FLAG_WRITE_INT); 04271 return ts; 04272 }
| static int tonepair_generator | ( | struct ast_channel * | chan, | |
| void * | data, | |||
| int | len, | |||
| int | samples | |||
| ) | [static] |
Definition at line 4274 of file channel.c.
References ast_log(), tonepair_state::data, tonepair_state::f, tonepair_state::fac1, tonepair_state::fac2, LOG_WARNING, tonepair_state::modulate, tonepair_state::v1_1, tonepair_state::v1_2, tonepair_state::v2_1, tonepair_state::v2_2, tonepair_state::v3_1, and tonepair_state::v3_2.
04275 { 04276 struct tonepair_state *ts = data; 04277 int x; 04278 04279 /* we need to prepare a frame with 16 * timelen samples as we're 04280 * generating SLIN audio 04281 */ 04282 len = samples * 2; 04283 04284 if (len > sizeof(ts->data) / 2 - 1) { 04285 ast_log(LOG_WARNING, "Can't generate that much data!\n"); 04286 return -1; 04287 } 04288 memset(&ts->f, 0, sizeof(ts->f)); 04289 for (x=0;x<len/2;x++) { 04290 ts->v1_1 = ts->v2_1; 04291 ts->v2_1 = ts->v3_1; 04292 ts->v3_1 = (ts->fac1 * ts->v2_1 >> 15) - ts->v1_1; 04293 04294 ts->v1_2 = ts->v2_2; 04295 ts->v2_2 = ts->v3_2; 04296 ts->v3_2 = (ts->fac2 * ts->v2_2 >> 15) - ts->v1_2; 04297 if (ts->modulate) { 04298 int p; 04299 p = ts->v3_2 - 32768; 04300 if (p < 0) p = -p; 04301 p = ((p * 9) / 10) + 1; 04302 ts->data[x] = (ts->v3_1 * p) >> 15; 04303 } else 04304 ts->data[x] = ts->v3_1 + ts->v3_2; 04305 } 04306 ts->f.frametype = AST_FRAME_VOICE; 04307 ts->f.subclass = AST_FORMAT_SLINEAR; 04308 ts->f.datalen = len; 04309 ts->f.samples = samples; 04310 ts->f.offset = AST_FRIENDLY_OFFSET; 04311 ts->f.data = ts->data; 04312 ast_write(chan, &ts->f); 04313 ts->pos += x; 04314 if (ts->duration > 0) { 04315 if (ts->pos >= ts->duration * 8) 04316 return -1; 04317 } 04318 return 0; 04319 }
| static void tonepair_release | ( | struct ast_channel * | chan, | |
| void * | params | |||
| ) | [static] |
Definition at line 4236 of file channel.c.
References ast_set_write_format(), free, and tonepair_state::origwfmt.
Referenced by tonepair_alloc().
04237 { 04238 struct tonepair_state *ts = params; 04239 04240 if (chan) 04241 ast_set_write_format(chan, ts->origwfmt); 04242 free(ts); 04243 }
void(*) ast_moh_cleanup_ptr(struct ast_channel *) = NULL [static] |
Definition at line 4394 of file channel.c.
Referenced by ast_install_music_functions(), ast_moh_cleanup(), and ast_uninstall_music_functions().
int(*) ast_moh_start_ptr(struct ast_channel *, const char *, const char *) = NULL [static] |
Definition at line 4392 of file channel.c.
Referenced by ast_install_music_functions(), ast_moh_start(), and ast_uninstall_music_functions().
void(*) ast_moh_stop_ptr(struct ast_channel *) = NULL [static] |
Definition at line 4393 of file channel.c.
Referenced by ast_install_music_functions(), ast_moh_stop(), and ast_uninstall_music_functions().
map AST_CAUSE's to readable string representations
Referenced by ast_cause2str(), ast_str2cause(), and dump_cause().
struct ast_cli_entry cli_channel[] [static] |
struct ast_cli_entry cli_show_channeltype_deprecated [static] |
Initial value:
{
{ "show", "channeltype", NULL },
show_channeltype_deprecated, NULL,
NULL, complete_channeltypes_deprecated }
struct ast_cli_entry cli_show_channeltypes_deprecated [static] |
Initial value:
{
{ "show", "channeltypes", NULL },
show_channeltypes, NULL,
NULL }
| unsigned long global_fin |
| unsigned long global_fout |
struct ast_channel_tech null_tech [static] |
char show_channeltype_usage[] [static] |
char show_channeltypes_usage[] [static] |
int shutting_down [static] |
Prevent new channel allocation if shutting down.
Definition at line 96 of file channel.c.
Referenced by ast_begin_shutdown(), ast_cancel_shutdown(), ast_channel_alloc(), and ast_shutting_down().
struct ast_generator silence_generator [static] |
Initial value:
{
.alloc = silence_generator_alloc,
.release = silence_generator_release,
.generate = silence_generator_generate,
}
Definition at line 4628 of file channel.c.
Referenced by ast_channel_start_silence_generator().
struct ast_generator tonepair [static] |
Initial value:
{
alloc: tonepair_alloc,
release: tonepair_release,
generate: tonepair_generator,
}
Definition at line 4321 of file channel.c.
Referenced by ast_tonepair_start().
1.5.1