Wed Aug 15 01:25:00 2007

Asterisk developer's documentation


channel.h File Reference

General Asterisk PBX channel definitions. More...

#include "asterisk/abstract_jb.h"
#include <unistd.h>
#include <sys/poll.h>
#include "asterisk/compat.h"
#include "asterisk/frame.h"
#include "asterisk/sched.h"
#include "asterisk/chanvars.h"
#include "asterisk/config.h"
#include "asterisk/lock.h"
#include "asterisk/cdr.h"
#include "asterisk/utils.h"
#include "asterisk/linkedlists.h"
#include "asterisk/stringfields.h"
#include "asterisk/compiler.h"

Include dependency graph for channel.h:

Go to the source code of this file.

Data Structures

struct  ast_bridge_config
struct  ast_callerid
 Structure for all kinds of caller ID identifications. More...
struct  ast_channel
 Main Channel structure associated with a channel. This is the side of it mostly used by the pbx and call management. More...
struct  ast_channel_tech
 Structure to describe a channel "technology", ie a channel driver See for examples:. More...
struct  ast_datastore
 Structure for a channel data store. More...
struct  ast_datastore_info
 Structure for a data store type. More...
struct  ast_generator
struct  outgoing_helper

Defines

#define AST_AGENT_FD   (AST_MAX_FDS-3)
#define AST_ALERT_FD   (AST_MAX_FDS-1)
#define AST_BRIDGE_DTMF_CHANNEL_0   (1 << 0)
 Report DTMF on channel 0.
#define AST_BRIDGE_DTMF_CHANNEL_1   (1 << 1)
 Report DTMF on channel 1.
#define AST_BRIDGE_IGNORE_SIGS   (1 << 4)
 Ignore all signal frames except NULL.
#define AST_BRIDGE_REC_CHANNEL_0   (1 << 2)
 Return all voice frames on channel 0.
#define AST_BRIDGE_REC_CHANNEL_1   (1 << 3)
 Return all voice frames on channel 1.
#define AST_CHANNEL_NAME   80
#define AST_GENERATOR_FD   (AST_MAX_FDS-4)
#define AST_MAX_CONTEXT   80
#define AST_MAX_EXTENSION   80
#define AST_MAX_FDS   8
#define AST_TIMING_FD   (AST_MAX_FDS-2)
#define CHECK_BLOCKING(c)
#define CRASH   do { } while(0)
#define DEBUGCHAN_FLAG   0x80000000
#define FRAMECOUNT_INC(x)   ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )
#define LOAD_OH(oh)
#define MAX_LANGUAGE   20
#define MAX_MUSICCLASS   80

Typedefs

typedef unsigned
long long 
ast_group_t

Enumerations

enum  { AST_CHAN_TP_WANTSJITTER = (1 << 0), AST_CHAN_TP_CREATESJITTER = (1 << 1) }
 ast_channel_tech Properties More...
enum  {
  AST_FLAG_DEFER_DTMF = (1 << 1), AST_FLAG_WRITE_INT = (1 << 2), AST_FLAG_BLOCKING = (1 << 3), AST_FLAG_ZOMBIE = (1 << 4),
  AST_FLAG_EXCEPTION = (1 << 5), AST_FLAG_MOH = (1 << 6), AST_FLAG_SPYING = (1 << 7), AST_FLAG_NBRIDGE = (1 << 8),
  AST_FLAG_IN_AUTOLOOP = (1 << 9), AST_FLAG_OUTGOING = (1 << 10), AST_FLAG_WHISPER = (1 << 11), AST_FLAG_IN_DTMF = (1 << 12),
  AST_FLAG_EMULATE_DTMF = (1 << 13), AST_FLAG_END_DTMF_ONLY = (1 << 14)
}
 ast_channel flags More...
enum  {
  AST_FEATURE_PLAY_WARNING = (1 << 0), AST_FEATURE_REDIRECT = (1 << 1), AST_FEATURE_DISCONNECT = (1 << 2), AST_FEATURE_ATXFER = (1 << 3),
  AST_FEATURE_AUTOMON = (1 << 4), AST_FEATURE_PARKCALL = (1 << 5)
}
 ast_bridge_config flags More...
enum  { AST_CDR_TRANSFER = (1 << 0), AST_CDR_FORWARD = (1 << 1), AST_CDR_CALLWAIT = (1 << 2), AST_CDR_CONFERENCE = (1 << 3) }
enum  {
  AST_SOFTHANGUP_DEV = (1 << 0), AST_SOFTHANGUP_ASYNCGOTO = (1 << 1), AST_SOFTHANGUP_SHUTDOWN = (1 << 2), AST_SOFTHANGUP_TIMEOUT = (1 << 3),
  AST_SOFTHANGUP_APPUNLOAD = (1 << 4), AST_SOFTHANGUP_EXPLICIT = (1 << 5), AST_SOFTHANGUP_UNBRIDGE = (1 << 6)
}
enum  ast_bridge_result { AST_BRIDGE_COMPLETE = 0, AST_BRIDGE_FAILED = -1, AST_BRIDGE_FAILED_NOWARN = -2, AST_BRIDGE_RETRY = -3 }
enum  ast_channel_adsicpe { AST_ADSI_UNKNOWN, AST_ADSI_AVAILABLE, AST_ADSI_UNAVAILABLE, AST_ADSI_OFFHOOKONLY }
enum  ast_channel_state {
  AST_STATE_DOWN, AST_STATE_RESERVED, AST_STATE_OFFHOOK, AST_STATE_DIALING,
  AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, AST_STATE_BUSY,
  AST_STATE_DIALING_OFFHOOK, AST_STATE_PRERING, AST_STATE_MUTE = (1 << 16)
}
 ast_channel states More...
enum  channelreloadreason { CHANNEL_MODULE_LOAD, CHANNEL_MODULE_RELOAD, CHANNEL_CLI_RELOAD, CHANNEL_MANAGER_RELOAD }
 Channel reload reasons for manager events at load or reload of configuration. More...

Functions

struct ast_channel__ast_request_and_dial (const char *type, int format, void *data, int timeout, int *reason, const char *cidnum, const char *cidname, 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
static int ast_add_fd (struct pollfd *pfd, int fd)
 if fd is a valid descriptor, set *pfd with the descriptor
int ast_answer (struct ast_channel *chan)
 Answer a ringing call.
int ast_autoservice_start (struct ast_channel *chan)
 Automatically service a channel for us...
int ast_autoservice_stop (struct ast_channel *chan)
 Stop servicing a channel for us...
void ast_begin_shutdown (int hangup)
 Initiate system shutdown.
int ast_best_codec (int fmts)
 Pick the best audio codec.
struct ast_channelast_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 state) attribute_pure
 Gives the string form of a given hangup cause.
void ast_change_name (struct ast_channel *chan, char *newname)
 Change channel name.
struct ast_channelast_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.
int 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.
struct ast_datastoreast_channel_datastore_alloc (const struct ast_datastore_info *info, char *uid)
 Create a channel datastore structure.
struct ast_datastoreast_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 *)
 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 *c0, struct ast_channel *c1)
 Makes two channel formats compatible.
int ast_channel_masquerade (struct ast_channel *original, struct ast_channel *clone)
 Weird function made for call transfers.
struct ast_frameast_channel_queryoption (struct ast_channel *channel, int option, void *data, int *datalen, int block)
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 *channel, int subclass, const char *data, int datalen)
int ast_channel_sendurl (struct ast_channel *channel, const char *url)
int ast_channel_setoption (struct ast_channel *channel, 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.
struct
ast_silence_generator
ast_channel_start_silence_generator (struct ast_channel *chan)
 Starts a silence generator on the given channel.
void ast_channel_stop_silence_generator (struct ast_channel *chan, struct ast_silence_generator *state)
 Stops a previously-started silence generator on the given channel.
int ast_channel_supports_html (struct ast_channel *channel)
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.
struct ast_channelast_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.
struct ast_variableast_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.
void ast_deactivate_generator (struct ast_channel *chan)
int ast_do_masquerade (struct ast_channel *chan)
 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 int ast_fdisset (struct pollfd *pfds, int fd, int max, int *start)
 Helper function for migrating select to poll.
struct ast_channelast_get_channel_by_exten_locked (const char *exten, const char *context)
 Get channel by exten (and optionally context) and lock it.
struct ast_channelast_get_channel_by_name_locked (const char *chan)
 Get channel by name (locks channel).
struct ast_channelast_get_channel_by_name_prefix_locked (const char *name, const int namelen)
 Get channel by name prefix (locks channel).
struct ast_channel_techast_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.
int ast_internal_timing_enabled (struct ast_channel *chan)
 Check if the channel can run in internal timing mode.
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 *f)
 Queue an outgoing frame.
int ast_queue_hangup (struct ast_channel *chan)
 Queue a hangup frame.
struct ast_frameast_read (struct ast_channel *chan)
 Reads a frame.
struct ast_frameast_read_noaudio (struct ast_channel *chan)
 Reads a frame, returning AST_FRAME_NULL frame if audio. Read a frame.
int ast_readstring (struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders)
int ast_readstring_full (struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd)
int ast_recvchar (struct ast_channel *chan, int timeout)
 Receives a text character from a channel.
char * ast_recvtext (struct ast_channel *chan, int timeout)
 Receives a text string from a channel Read a string of text from a channel.
struct ast_channelast_request (const char *type, int format, void *data, int *status)
 Requests a channel.
struct ast_channelast_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.
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
static int ast_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp)
 Waits for activity on a group of channels.
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)
int ast_senddigit_end (struct ast_channel *chan, char digit, unsigned int duration)
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 *cidnum, const char *cidname, const char *ani)
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.
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 format)
 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)
 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)
 Gives the string form of a given channel state.
int ast_str2cause (const char *name) attribute_pure
 Convert a symbolic hangup cause to number.
int ast_tonepair (struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
int ast_tonepair_start (struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
void ast_tonepair_stop (struct ast_channel *chan)
int ast_transfer (struct ast_channel *chan, char *dest)
 Transfer a channel (if supported). Returns -1 on error, 0 if not supported and 1 if supported and requested.
char * ast_transfercapability2str (int transfercapability) attribute_const
 Gives the string form of a given transfer capability.
int ast_waitfor (struct ast_channel *chan, int ms)
 Wait for input on a channel.
struct ast_channelast_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.
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.
struct ast_channelast_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.
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 ctrlfd)
 Wait for a digit Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
struct ast_channelast_walk_channel_by_exten_locked (const struct ast_channel *chan, const char *exten, const char *context)
 Get next channel by exten (and optionally context) and lock it.
struct ast_channelast_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 *frame)
 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 *frame)
 Write video frame to a channel This function writes the given frame to the indicated channel.
const char * channelreloadreason2txt (enum channelreloadreason reason)
 Convert enum channelreloadreason to text string for manager event.


Detailed Description

General Asterisk PBX channel definitions.

See also:

Definition in file channel.h.


Define Documentation

#define AST_AGENT_FD   (AST_MAX_FDS-3)

used by agents for pass through

Definition at line 129 of file channel.h.

Referenced by agent_read().

#define AST_ALERT_FD   (AST_MAX_FDS-1)

used for alertpipe

Definition at line 127 of file channel.h.

Referenced by ast_channel_alloc(), and restore_channel().

#define AST_BRIDGE_DTMF_CHANNEL_0   (1 << 0)

Report DTMF on channel 0.

Definition at line 959 of file channel.h.

Referenced by ast_generic_bridge(), ast_rtp_bridge(), bridge_native_loop(), bridge_p2p_loop(), iax2_bridge(), misdn_bridge(), set_config_flags(), and zt_bridge().

#define AST_BRIDGE_DTMF_CHANNEL_1   (1 << 1)

Report DTMF on channel 1.

Definition at line 961 of file channel.h.

Referenced by ast_generic_bridge(), ast_rtp_bridge(), bridge_native_loop(), bridge_p2p_loop(), iax2_bridge(), misdn_bridge(), set_config_flags(), and zt_bridge().

#define AST_BRIDGE_IGNORE_SIGS   (1 << 4)

Ignore all signal frames except NULL.

Definition at line 967 of file channel.h.

Referenced by ast_generic_bridge(), bridge_native_loop(), bridge_p2p_loop(), and iax2_bridge().

#define AST_BRIDGE_REC_CHANNEL_0   (1 << 2)

Return all voice frames on channel 0.

Definition at line 963 of file channel.h.

#define AST_BRIDGE_REC_CHANNEL_1   (1 << 3)

Return all voice frames on channel 1.

Definition at line 965 of file channel.h.

#define AST_CHANNEL_NAME   80

Max length of an ast_channel name

Definition at line 105 of file channel.h.

Referenced by ast_channel_free(), ast_parse_device_state(), create_jb(), fast_originate(), page_exec(), and softhangup_exec().

#define AST_GENERATOR_FD   (AST_MAX_FDS-4)

used by generator

Definition at line 130 of file channel.h.

Referenced by __ast_read(), ast_deactivate_generator(), and ast_do_masquerade().

#define AST_MAX_CONTEXT   80

Max length of a context

Definition at line 104 of file channel.h.

Referenced by _macro_exec(), cleanup_stale_contexts(), conf_run(), reload_config(), and try_calling().

#define AST_MAX_EXTENSION   80

Max length of an extension

Definition at line 103 of file channel.h.

Referenced by advanced_options(), ast_device_state_changed(), ast_extension_state2(), ast_hint_state_changed(), ast_ivr_menu_run_internal(), begin_dial(), conf_run(), destroy_station(), disa_exec(), do_parking_thread(), dundi_lookup_local(), forward_message(), function_enum(), get_destination(), gosub_exec(), load_config(), log_exec(), mgcp_ss(), park_add_hints(), phone_check_exception(), realtime_switch_common(), show_dialplan_helper(), skinny_answer(), skinny_indicate(), skinny_ss(), sla_build_station(), speech_background(), ss_thread(), transmit_state_notify(), try_calling(), vm_authenticate(), vmauthenticate(), and wait_for_answer().

#define AST_MAX_FDS   8

Definition at line 122 of file channel.h.

Referenced by ast_channel_alloc(), ast_do_masquerade(), ast_waitfor_nandfds(), do_parking_thread(), and update_features().

#define AST_TIMING_FD   (AST_MAX_FDS-2)

used for timingfd

Definition at line 128 of file channel.h.

Referenced by __ast_read(), agent_read(), ast_channel_alloc(), ast_do_masquerade(), and restore_channel().

#define CHECK_BLOCKING (  ) 

Definition at line 1311 of file channel.h.

Referenced by ast_sendtext(), ast_waitfor_nandfds(), ast_write(), phone_read(), and zt_read().

#define CRASH   do { } while(0)

Definition at line 1308 of file channel.h.

Referenced by agent_new(), ast_hangup(), ast_queue_frame(), ast_rtcp_read(), ast_rtp_read(), ast_sched_del(), ast_udptl_read(), create_jb(), and jb_get_and_deliver().

#define DEBUGCHAN_FLAG   0x80000000

Definition at line 272 of file channel.h.

Referenced by __ast_read(), ast_write(), handle_core_set_debug_channel(), handle_debugchan_deprecated(), handle_nodebugchan_deprecated(), handle_showchan(), handle_showchan_deprecated(), and serialize_showchan().

#define FRAMECOUNT_INC (  )     ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )

Definition at line 273 of file channel.h.

Referenced by __ast_read(), and ast_write().

#define LOAD_OH ( oh   ) 

Definition at line 510 of file channel.h.

Referenced by ast_pbx_outgoing_exten().

#define MAX_LANGUAGE   20

Max length of the language setting

Definition at line 106 of file channel.h.

#define MAX_MUSICCLASS   80

Max length of the music class setting

Definition at line 107 of file channel.h.


Typedef Documentation

typedef unsigned long long ast_group_t

Definition at line 139 of file channel.h.


Enumeration Type Documentation

anonymous enum

ast_channel_tech Properties

Enumerator:
AST_CHAN_TP_WANTSJITTER  Channels have this property if they can accept input with jitter; i.e. most VoIP channels.
AST_CHAN_TP_CREATESJITTER  Channels have this property if they can create jitter; i.e. most VoIP channels.

Definition at line 438 of file channel.h.

00438      {
00439    /*! \brief Channels have this property if they can accept input with jitter; 
00440     *         i.e. most VoIP channels */
00441    AST_CHAN_TP_WANTSJITTER = (1 << 0),
00442    /*! \brief Channels have this property if they can create jitter; 
00443     *         i.e. most VoIP channels */
00444    AST_CHAN_TP_CREATESJITTER = (1 << 1),
00445 };

anonymous enum

ast_channel flags

Enumerator:
AST_FLAG_DEFER_DTMF  Queue incoming dtmf, to be released when this flag is turned off
AST_FLAG_WRITE_INT  write should be interrupt generator
AST_FLAG_BLOCKING  a thread is blocking on this channel
AST_FLAG_ZOMBIE  This is a zombie channel
AST_FLAG_EXCEPTION  There is an exception pending
AST_FLAG_MOH  Listening to moh XXX anthm promises me this will disappear XXX
AST_FLAG_SPYING  This channel is spying on another channel
AST_FLAG_NBRIDGE  This channel is in a native bridge
AST_FLAG_IN_AUTOLOOP  the channel is in an auto-incrementing dialplan processor, so when ->priority is set, it will get incremented before finding the next priority to run
AST_FLAG_OUTGOING  This is an outgoing call
AST_FLAG_WHISPER  This channel is being whispered on
AST_FLAG_IN_DTMF  A DTMF_BEGIN frame has been read from this channel, but not yet an END
AST_FLAG_EMULATE_DTMF  A DTMF_END was received when not IN_DTMF, so the length of the digit is currently being emulated
AST_FLAG_END_DTMF_ONLY  This is set to tell the channel not to generate DTMF begin frames, and to instead only generate END frames.

Definition at line 448 of file channel.h.

00448      {
00449    /*! Queue incoming dtmf, to be released when this flag is turned off */
00450    AST_FLAG_DEFER_DTMF =    (1 << 1),
00451    /*! write should be interrupt generator */
00452    AST_FLAG_WRITE_INT =     (1 << 2),
00453    /*! a thread is blocking on this channel */
00454    AST_FLAG_BLOCKING =      (1 << 3),
00455    /*! This is a zombie channel */
00456    AST_FLAG_ZOMBIE =        (1 << 4),
00457    /*! There is an exception pending */
00458    AST_FLAG_EXCEPTION =     (1 << 5),
00459    /*! Listening to moh XXX anthm promises me this will disappear XXX */
00460    AST_FLAG_MOH =           (1 << 6),
00461    /*! This channel is spying on another channel */
00462    AST_FLAG_SPYING =        (1 << 7),
00463    /*! This channel is in a native bridge */
00464    AST_FLAG_NBRIDGE =       (1 << 8),
00465    /*! the channel is in an auto-incrementing dialplan processor,
00466     *  so when ->priority is set, it will get incremented before
00467     *  finding the next priority to run */
00468    AST_FLAG_IN_AUTOLOOP =   (1 << 9),
00469    /*! This is an outgoing call */
00470    AST_FLAG_OUTGOING =      (1 << 10),
00471    /*! This channel is being whispered on */
00472    AST_FLAG_WHISPER =       (1 << 11),
00473    /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
00474    AST_FLAG_IN_DTMF =       (1 << 12),
00475    /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is 
00476     *  currently being emulated */
00477    AST_FLAG_EMULATE_DTMF =  (1 << 13),
00478    /*! This is set to tell the channel not to generate DTMF begin frames, and
00479     *  to instead only generate END frames. */
00480    AST_FLAG_END_DTMF_ONLY = (1 << 14),
00481 };

anonymous enum

ast_bridge_config flags

Enumerator:
AST_FEATURE_PLAY_WARNING 
AST_FEATURE_REDIRECT 
AST_FEATURE_DISCONNECT 
AST_FEATURE_ATXFER 
AST_FEATURE_AUTOMON 
AST_FEATURE_PARKCALL 

Definition at line 484 of file channel.h.

00484      {
00485    AST_FEATURE_PLAY_WARNING = (1 << 0),
00486    AST_FEATURE_REDIRECT =     (1 << 1),
00487    AST_FEATURE_DISCONNECT =   (1 << 2),
00488    AST_FEATURE_ATXFER =       (1 << 3),
00489    AST_FEATURE_AUTOMON =      (1 << 4),
00490    AST_FEATURE_PARKCALL =     (1 << 5),
00491 };

anonymous enum

Enumerator:
AST_CDR_TRANSFER 
AST_CDR_FORWARD 
AST_CDR_CALLWAIT 
AST_CDR_CONFERENCE 

Definition at line 532 of file channel.h.

00532      {
00533    AST_CDR_TRANSFER =   (1 << 0),
00534    AST_CDR_FORWARD =    (1 << 1),
00535    AST_CDR_CALLWAIT =   (1 << 2),
00536    AST_CDR_CONFERENCE = (1 << 3),
00537 };

anonymous enum

Enumerator:
AST_SOFTHANGUP_DEV  Soft hangup by device
AST_SOFTHANGUP_ASYNCGOTO  Soft hangup for async goto
AST_SOFTHANGUP_SHUTDOWN 
AST_SOFTHANGUP_TIMEOUT 
AST_SOFTHANGUP_APPUNLOAD 
AST_SOFTHANGUP_EXPLICIT 
AST_SOFTHANGUP_UNBRIDGE 

Definition at line 539 of file channel.h.

00539      {
00540    /*! Soft hangup by device */
00541    AST_SOFTHANGUP_DEV =       (1 << 0),
00542    /*! Soft hangup for async goto */
00543    AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
00544    AST_SOFTHANGUP_SHUTDOWN =  (1 << 2),
00545    AST_SOFTHANGUP_TIMEOUT =   (1 << 3),
00546    AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
00547    AST_SOFTHANGUP_EXPLICIT =  (1 << 5),
00548    AST_SOFTHANGUP_UNBRIDGE =  (1 << 6),
00549 };

enum ast_bridge_result

Enumerator:
AST_BRIDGE_COMPLETE 
AST_BRIDGE_FAILED 
AST_BRIDGE_FAILED_NOWARN 
AST_BRIDGE_RETRY 

Definition at line 132 of file channel.h.

00132                        {
00133    AST_BRIDGE_COMPLETE = 0,
00134    AST_BRIDGE_FAILED = -1,
00135    AST_BRIDGE_FAILED_NOWARN = -2,
00136    AST_BRIDGE_RETRY = -3,
00137 };

enum ast_channel_adsicpe

Enumerator:
AST_ADSI_UNKNOWN 
AST_ADSI_AVAILABLE 
AST_ADSI_UNAVAILABLE 
AST_ADSI_OFFHOOKONLY 

Definition at line 275 of file channel.h.

enum ast_channel_state

ast_channel states

Note:
Bits 0-15 of state are reserved for the state (up/down) of the line Bits 16-32 of state are reserved for flags
Enumerator:
AST_STATE_DOWN  Channel is down and available
AST_STATE_RESERVED  Channel is down, but reserved
AST_STATE_OFFHOOK  Channel is off hook
AST_STATE_DIALING  Digits (or equivalent) have been dialed
AST_STATE_RING  Line is ringing
AST_STATE_RINGING  Remote end is ringing
AST_STATE_UP  Line is up
AST_STATE_BUSY  Line is busy
AST_STATE_DIALING_OFFHOOK  Digits (or equivalent) have been dialed while offhook
AST_STATE_PRERING  Channel has detected an incoming call and is waiting for ring
AST_STATE_MUTE  Do not transmit voice data

Definition at line 288 of file channel.h.

00288                        {
00289    /*! Channel is down and available */
00290    AST_STATE_DOWN,
00291    /*! Channel is down, but reserved */
00292    AST_STATE_RESERVED,
00293    /*! Channel is off hook */
00294    AST_STATE_OFFHOOK,
00295    /*! Digits (or equivalent) have been dialed */
00296    AST_STATE_DIALING,
00297    /*! Line is ringing */
00298    AST_STATE_RING,
00299    /*! Remote end is ringing */
00300    AST_STATE_RINGING,
00301    /*! Line is up */
00302    AST_STATE_UP,
00303    /*! Line is busy */
00304    AST_STATE_BUSY,
00305    /*! Digits (or equivalent) have been dialed while offhook */
00306    AST_STATE_DIALING_OFFHOOK,
00307    /*! Channel has detected an incoming call and is waiting for ring */
00308    AST_STATE_PRERING,
00309 
00310    /*! Do not transmit voice data */
00311    AST_STATE_MUTE = (1 << 16),
00312 };

enum channelreloadreason

Channel reload reasons for manager events at load or reload of configuration.

Enumerator:
CHANNEL_MODULE_LOAD 
CHANNEL_MODULE_RELOAD 
CHANNEL_CLI_RELOAD 
CHANNEL_MANAGER_RELOAD 

Definition at line 553 of file channel.h.


Function Documentation

struct ast_channel* __ast_request_and_dial ( const char *  type,
int  format,
void *  data,
int  timeout,
int *  reason,
const char *  cidnum,
const char *  cidname,
struct outgoing_helper oh 
) [read]

Definition at line 3037 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, ast_channel::context, outgoing_helper::context, ast_channel::exten, outgoing_helper::exten, f, ast_frame::frametype, ast_channel::hangupcause, LOG_NOTICE, outgoing_helper::parent_channel, ast_channel::priority, outgoing_helper::priority, ast_frame::subclass, and outgoing_helper::vars.

03038 {
03039    int dummy_outstate;
03040    int cause = 0;
03041    struct ast_channel *chan;
03042    int res = 0;
03043    
03044    if (outstate)
03045       *outstate = 0;
03046    else
03047       outstate = &dummy_outstate;   /* make outstate always a valid pointer */
03048 
03049    chan = ast_request(type, format, data, &cause);
03050    if (!chan) {
03051       ast_log(LOG_NOTICE, "Unable to request channel %s/%s\n", type, (char *)data);
03052       /* compute error and return */
03053       if (cause == AST_CAUSE_BUSY)
03054          *outstate = AST_CONTROL_BUSY;
03055       else if (cause == AST_CAUSE_CONGESTION)
03056          *outstate = AST_CONTROL_CONGESTION;
03057       return NULL;
03058    }
03059 
03060    if (oh) {
03061       if (oh->vars)  
03062          ast_set_variables(chan, oh->vars);
03063       /* XXX why is this necessary, for the parent_channel perhaps ? */
03064       if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name))
03065          ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num);
03066       if (oh->parent_channel)
03067          ast_channel_inherit_variables(oh->parent_channel, chan);
03068       if (oh->account)
03069          ast_cdr_setaccount(chan, oh->account); 
03070    }
03071    ast_set_callerid(chan, cid_num, cid_name, cid_num);
03072 
03073    
03074 
03075    if (!chan->cdr) { /* up till now, this insertion hasn't been done. Therefore,
03076             to keep from throwing off the basic order of the universe,
03077             we will try to keep this cdr from getting posted. */
03078       chan->cdr = ast_cdr_alloc();
03079       ast_cdr_init(chan->cdr, chan);
03080       ast_cdr_start(chan->cdr);
03081    }
03082    if (ast_call(chan, data, 0)) {   /* ast_call failed... */
03083       ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data);
03084    } else {
03085       res = 1; /* mark success in case chan->_state is already AST_STATE_UP */
03086       while (timeout && chan->_state != AST_STATE_UP) {
03087          struct ast_frame *f;
03088          res = ast_waitfor(chan, timeout);
03089          if (res <= 0) /* error, timeout, or done */
03090             break;
03091          if (timeout > -1)
03092             timeout = res;
03093          f = ast_read(chan);
03094          if (!f) {
03095             *outstate = AST_CONTROL_HANGUP;
03096             res = 0;
03097             break;
03098          }
03099          if (f->frametype == AST_FRAME_CONTROL) {
03100             switch (f->subclass) {
03101             case AST_CONTROL_RINGING:  /* record but keep going */
03102                *outstate = f->subclass;
03103                break;
03104 
03105             case AST_CONTROL_BUSY:
03106             case AST_CONTROL_CONGESTION:
03107             case AST_CONTROL_ANSWER:
03108                *outstate = f->subclass;
03109                timeout = 0;      /* trick to force exit from the while() */
03110                break;
03111 
03112             /* Ignore these */
03113             case AST_CONTROL_PROGRESS:
03114             case AST_CONTROL_PROCEEDING:
03115             case AST_CONTROL_HOLD:
03116             case AST_CONTROL_UNHOLD:
03117             case AST_CONTROL_VIDUPDATE:
03118             case -1:       /* Ignore -- just stopping indications */
03119                break;
03120 
03121             default:
03122                ast_log(LOG_NOTICE, "Don't know what to do with control frame %d\n", f->subclass);
03123             }
03124          }
03125          ast_frfree(f);
03126       }
03127    }
03128 
03129    /* Final fixups */
03130    if (oh) {
03131       if (!ast_strlen_zero(oh->context))
03132          ast_copy_string(chan->context, oh->context, sizeof(chan->context));
03133       if (!ast_strlen_zero(oh->exten))
03134          ast_copy_string(chan->exten, oh->exten, sizeof(chan->exten));
03135       if (oh->priority) 
03136          chan->priority = oh->priority;
03137    }
03138    if (chan->_state == AST_STATE_UP)
03139       *outstate = AST_CONTROL_ANSWER;
03140 
03141    if (res <= 0) {
03142       if (!chan->cdr && (chan->cdr = ast_cdr_alloc()))
03143          ast_cdr_init(chan->cdr, chan);
03144       if (chan->cdr) {
03145          char tmp[256];
03146          snprintf(tmp, sizeof(tmp), "%s/%s", type, (char *)data);
03147          ast_cdr_setapp(chan->cdr,"Dial",tmp);
03148          ast_cdr_update(chan);
03149          ast_cdr_start(chan->cdr);
03150          ast_cdr_end(chan->cdr);
03151          /* If the cause wasn't handled properly */
03152          if (ast_cdr_disposition(chan->cdr,chan->hangupcause))
03153             ast_cdr_failed(chan->cdr);
03154       }
03155       ast_hangup(chan);
03156       chan = NULL;
03157    }
03158    return chan;
03159 }

int ast_activate_generator ( struct ast_channel chan,
struct ast_generator gen,
void *  params 
)

Activate a given generator

Definition at line 1858 of file channel.c.

References ast_generator::alloc, ast_channel_lock, ast_channel_unlock, ast_prod(), ast_settimeout(), ast_channel::generator, generator_force(), ast_channel::generatordata, and ast_generator::release.

01859 {
01860    int res = 0;
01861 
01862    ast_channel_lock(chan);
01863 
01864    if (chan->generatordata) {
01865       if (chan->generator && chan->generator->release)
01866          chan->generator->release(chan, chan->generatordata);
01867       chan->generatordata = NULL;
01868    }
01869 
01870    ast_prod(chan);
01871    if (gen->alloc && !(chan->generatordata = gen->alloc(chan, params))) {
01872       res = -1;
01873    }
01874    
01875    if (!res) {
01876       ast_settimeout(chan, 160, generator_force, chan);
01877       chan->generator = gen;
01878    }
01879 
01880    ast_channel_unlock(chan);
01881 
01882    return res;
01883 }

int ast_active_channels ( void   ) 

returns number of active/allocated channels

Returns number of active/allocated channels

Definition at line 462 of file channel.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, and AST_LIST_UNLOCK.

00463 {
00464    struct ast_channel *c;
00465    int cnt = 0;
00466    AST_LIST_LOCK(&channels);
00467    AST_LIST_TRAVERSE(&channels, c, chan_list)
00468       cnt++;
00469    AST_LIST_UNLOCK(&channels);
00470    return cnt;
00471 }

static int ast_add_fd ( struct pollfd pfd,
int  fd 
) [inline, static]

if fd is a valid descriptor, set *pfd with the descriptor

Returns:
Return 1 (not -1!) if added, 0 otherwise (so we can add the return value to the index into the array)

Definition at line 1230 of file channel.h.

References pollfd::events, pollfd::fd, POLLIN, and POLLPRI.

Referenced by ast_waitfor_nandfds().

01231 {
01232    pfd->fd = fd;
01233    pfd->events = POLLIN | POLLPRI;
01234    return fd >= 0;
01235 }

int ast_answer ( struct ast_channel chan  ) 

Answer a ringing call.

Parameters:
chan channel to answer This function answers a channel and handles all necessary call setup functions.
Returns:
Returns 0 on success, -1 on failure

Definition at line 1791 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.

01792 {
01793    int res = 0;
01794    ast_channel_lock(chan);
01795    /* You can't answer an outbound call */
01796    if (ast_test_flag(chan, AST_FLAG_OUTGOING)) {
01797       ast_channel_unlock(chan);
01798       return 0;
01799    }
01800    /* Stop if we're a zombie or need a soft hangup */
01801    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
01802       ast_channel_unlock(chan);
01803       return -1;
01804    }
01805    switch(chan->_state) {
01806    case AST_STATE_RINGING:
01807    case AST_STATE_RING:
01808       if (chan->tech->answer)
01809          res = chan->tech->answer(chan);
01810       ast_setstate(chan, AST_STATE_UP);
01811       ast_cdr_answer(chan->cdr);
01812       break;
01813    case AST_STATE_UP:
01814       ast_cdr_answer(chan->cdr);
01815       break;
01816    default:
01817       break;
01818    }
01819    ast_channel_unlock(chan);
01820    return res;
01821 }

int ast_autoservice_start ( struct ast_channel chan  ) 

Automatically service a channel for us...

Return values:
0 success
-1 failure, or the channel is already being autoserviced

Definition at line 96 of file autoservice.c.

References ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_pthread_create_background, AST_PTHREADT_NULL, asthread, autoservice_run(), asent::chan, free, and LOG_WARNING.

00097 {
00098    int res = -1;
00099    struct asent *as;
00100    AST_LIST_LOCK(&aslist);
00101 
00102    /* Check if the channel already has autoservice */
00103    AST_LIST_TRAVERSE(&aslist, as, list) {
00104       if (as->chan == chan)
00105          break;
00106    }
00107 
00108    /* If not, start autoservice on channel */
00109    if (!as && (as = ast_calloc(1, sizeof(*as)))) {
00110       as->chan = chan;
00111       AST_LIST_INSERT_HEAD(&aslist, as, list);
00112       res = 0;
00113       if (asthread == AST_PTHREADT_NULL) { /* need start the thread */
00114          if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) {
00115             ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
00116             /* There will only be a single member in the list at this point,
00117                the one we just added. */
00118             AST_LIST_REMOVE(&aslist, as, list);
00119             free(as);
00120             res = -1;
00121          } else
00122             pthread_kill(asthread, SIGURG);
00123       }
00124    }
00125    AST_LIST_UNLOCK(&aslist);
00126    return res;
00127 }

int ast_autoservice_stop ( struct ast_channel chan  ) 

Stop servicing a channel for us...

Return values:
0 success
-1 error, or the channel has been hungup

Definition at line 129 of file autoservice.c.

References ast_channel::_softhangup, AST_FLAG_BLOCKING, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, AST_PTHREADT_NULL, ast_test_flag, asthread, asent::chan, and free.

00130 {
00131    int res = -1;
00132    struct asent *as;
00133 
00134    AST_LIST_LOCK(&aslist);
00135    AST_LIST_TRAVERSE_SAFE_BEGIN(&aslist, as, list) {  
00136       if (as->chan == chan) {
00137          AST_LIST_REMOVE_CURRENT(&aslist, list);
00138          free(as);
00139          if (!chan->_softhangup)
00140             res = 0;
00141          break;
00142       }
00143    }
00144    AST_LIST_TRAVERSE_SAFE_END
00145 
00146    if (asthread != AST_PTHREADT_NULL) 
00147       pthread_kill(asthread, SIGURG);
00148    AST_LIST_UNLOCK(&aslist);
00149 
00150    /* Wait for it to un-block */
00151    while(ast_test_flag(chan, AST_FLAG_BLOCKING))
00152       usleep(1000);
00153    return res;
00154 }

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 449 of file channel.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_softhangup(), AST_SOFTHANGUP_SHUTDOWN, and shutting_down.

00450 {
00451    struct ast_channel *c;
00452    shutting_down = 1;
00453    if (hangup) {
00454       AST_LIST_LOCK(&channels);
00455       AST_LIST_TRAVERSE(&channels, c, chan_list)
00456          ast_softhangup(c, AST_SOFTHANGUP_SHUTDOWN);
00457       AST_LIST_UNLOCK(&channels);
00458    }
00459 }

int ast_best_codec ( int  fmts  ) 

Pick the best audio codec.

Pick the best codec

Okay, ulaw is used by all telephony equipment, so start with it

Unless of course, you're a silly European, so then prefer ALAW

G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority

Okay, well, signed linear is easy to translate into other stuff

G.726 is standard ADPCM, in RFC3551 packing order

G.726 is standard ADPCM, in AAL2 packing order

ADPCM has great sound quality and is still pretty easy to translate

Okay, we're down to vocoders now, so pick GSM because it's small and easier to translate and sounds pretty good

iLBC is not too bad

Speex is free, but computationally more expensive than GSM

Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough to use it

G.729a is faster than 723 and slightly less expensive

Down to G.723.1 which is proprietary but at least designed for voice

Definition at line 674 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.

00675 {
00676    /* This just our opinion, expressed in code.  We are asked to choose
00677       the best codec to use, given no information */
00678    int x;
00679    static int prefs[] =
00680    {
00681       /*! Okay, ulaw is used by all telephony equipment, so start with it */
00682       AST_FORMAT_ULAW,
00683       /*! Unless of course, you're a silly European, so then prefer ALAW */
00684       AST_FORMAT_ALAW,
00685       /*! G.722 is better then all below, but not as common as the above... so give ulaw and alaw priority */
00686       AST_FORMAT_G722,
00687       /*! Okay, well, signed linear is easy to translate into other stuff */
00688       AST_FORMAT_SLINEAR,
00689       /*! G.726 is standard ADPCM, in RFC3551 packing order */
00690       AST_FORMAT_G726,
00691       /*! G.726 is standard ADPCM, in AAL2 packing order */
00692       AST_FORMAT_G726_AAL2,
00693       /*! ADPCM has great sound quality and is still pretty easy to translate */
00694       AST_FORMAT_ADPCM,
00695       /*! Okay, we're down to vocoders now, so pick GSM because it's small and easier to
00696           translate and sounds pretty good */
00697       AST_FORMAT_GSM,
00698       /*! iLBC is not too bad */
00699       AST_FORMAT_ILBC,
00700       /*! Speex is free, but computationally more expensive than GSM */
00701       AST_FORMAT_SPEEX,
00702       /*! Ick, LPC10 sounds terrible, but at least we have code for it, if you're tacky enough
00703           to use it */
00704       AST_FORMAT_LPC10,
00705       /*! G.729a is faster than 723 and slightly less expensive */
00706       AST_FORMAT_G729A,
00707       /*! Down to G.723.1 which is proprietary but at least designed for voice */
00708       AST_FORMAT_G723_1,
00709    };
00710 
00711    /* Strip out video */
00712    fmts &= AST_FORMAT_AUDIO_MASK;
00713    
00714    /* Find the first preferred codec in the format given */
00715    for (x=0; x < (sizeof(prefs) / sizeof(prefs[0]) ); x++)
00716       if (fmts & prefs[x])
00717          return prefs[x];
00718    ast_log(LOG_WARNING, "Don't know any of 0x%x formats\n", fmts);
00719    return 0;
00720 }

struct ast_channel* ast_bridged_channel ( struct ast_channel chan  )  [read]

Find bridged channel.

Parameters:
chan Current channel

Definition at line 3873 of file channel.c.

References ast_channel::_bridge, ast_channel_tech::bridged_channel, and ast_channel::tech.

03874 {
03875    struct ast_channel *bridged;
03876    bridged = chan->_bridge;
03877    if (bridged && bridged->tech->bridged_channel)
03878       bridged = bridged->tech->bridged_channel(chan, bridged);
03879    return bridged;
03880 }

int ast_call ( struct ast_channel chan,
char *  addr,
int  timeout 
)

Make a call.

Parameters:
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.
Returns:
Returns -1 on failure, 0 on not enough time (does not automatically stop ringing), and the number of seconds the connect took otherwise.

Definition at line 3216 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.

03217 {
03218    /* Place an outgoing call, but don't wait any longer than timeout ms before returning.
03219       If the remote end does not answer within the timeout, then do NOT hang up, but
03220       return anyway.  */
03221    int res = -1;
03222    /* Stop if we're a zombie or need a soft hangup */
03223    ast_channel_lock(chan);
03224    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {
03225       if (chan->tech->call)
03226          res = chan->tech->call(chan, addr, timeout);
03227       ast_set_flag(chan, AST_FLAG_OUTGOING);
03228    }
03229    ast_channel_unlock(chan);
03230    return res;
03231 }

void ast_cancel_shutdown ( void   ) 

Cancel a shutdown in progress.

Cancels an existing shutdown and returns to normal operation

Definition at line 474 of file channel.c.

References shutting_down.

00475 {
00476    shutting_down = 0;
00477 }

const char* ast_cause2str ( int  state  ) 

Gives the string form of a given hangup cause.

Gives the string form of a given cause code

Parameters:
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 594 of file channel.c.

References causes, and ast_cause::desc.

00595 {
00596    int x;
00597 
00598    for (x=0; x < sizeof(causes) / sizeof(causes[0]); x++) {
00599       if (causes[x].cause == cause)
00600          return causes[x].desc;
00601    }
00602 
00603    return "Unknown";
00604 }

void ast_change_name ( struct ast_channel chan,
char *  newname 
)

Change channel name.

Definition at line 3448 of file channel.c.

References ast_string_field_set, EVENT_FLAG_CALL, manager_event(), and name.

03449 {
03450    manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", chan->name, newname, chan->uniqueid);
03451    ast_string_field_set(chan, name, newname);
03452 }

struct ast_channel* ast_channel_alloc ( int  needqueue,
int  state,
const char *  cid_num,
const char *  cid_name,
const char *  acctcode,
const char *  exten,
const char *  context,
const int  amaflag,
const char *  name_fmt,
  ... 
) [read]

Create a channel structure.

Returns:
Returns NULL on failure to allocate.
Note:
New channels are by default set to the "default" context and extension "s"

Definition at line 728 of file channel.c.

References ast_channel::_state, accountcode, ast_channel::alertpipe, ast_channel::amaflags, AST_ALERT_FD, ast_calloc, ast_cdr_alloc(), ast_cdr_init(), ast_cdr_start(), ast_config_AST_SYSTEM_NAME, ast_default_accountcode, ast_default_amaflags, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_log(), AST_MAX_FDS, ast_mutex_init(), ast_state2str(), ast_strdup, ast_string_field_build, ast_string_field_build_va, ast_string_field_free_pools, ast_string_field_init, ast_string_field_set, ast_strlen_zero(), AST_TIMING_FD, ast_channel::cdr, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, ast_channel::context, defaultlanguage, EVENT_FLAG_CALL, ast_channel::exten, ast_channel::fds, ast_channel::fin, ast_channel::flags, ast_channel::fout, free, global_fin, global_fout, HAVE_ZAPTEL, language, ast_channel::lock, LOG_WARNING, manager_event(), name, null_tech, ast_channel::priority, S_OR, ast_channel::sched, sched_context_create(), sched_context_destroy(), shutting_down, ast_channel::streamid, ast_channel::tech, ast_channel::timingfd, uniqueint, and ast_channel::varshead.

00729 {
00730    struct ast_channel *tmp;
00731    int x;
00732    int flags;
00733    struct varshead *headp;
00734    va_list ap1, ap2;
00735 
00736    /* If shutting down, don't allocate any new channels */
00737    if (shutting_down) {
00738       ast_log(LOG_WARNING, "Channel allocation failed: Refusing due to active shutdown\n");
00739       return NULL;
00740    }
00741 
00742    if (!(tmp = ast_calloc(1, sizeof(*tmp))))
00743       return NULL;
00744 
00745    if (!(tmp->sched = sched_context_create())) {
00746       ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n");
00747       free(tmp);
00748       return NULL;
00749    }
00750    
00751    if ((ast_string_field_init(tmp, 128))) {
00752       sched_context_destroy(tmp->sched);
00753       free(tmp);
00754       return NULL;
00755    }
00756 
00757    /* Don't bother initializing the last two FD here, because they
00758       will *always* be set just a few lines down (AST_TIMING_FD,
00759       AST_ALERT_FD). */
00760    for (x = 0; x < AST_MAX_FDS - 2; x++)
00761       tmp->fds[x] = -1;
00762 
00763 #ifdef HAVE_ZAPTEL
00764    tmp->timingfd = open("/dev/zap/timer", O_RDWR);
00765    if (tmp->timingfd > -1) {
00766       /* Check if timing interface supports new
00767          ping/pong scheme */
00768       flags = 1;
00769       if (!ioctl(tmp->timingfd, ZT_TIMERPONG, &flags))
00770          needqueue = 0;
00771    }
00772 #else
00773    tmp->timingfd = -1;              
00774 #endif               
00775 
00776    if (needqueue) {
00777       if (pipe(tmp->alertpipe)) {
00778          ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe!\n");
00779          ast_string_field_free_pools(tmp);
00780          free(tmp);
00781          return NULL;
00782       } else {
00783          flags = fcntl(tmp->alertpipe[0], F_GETFL);
00784          fcntl(tmp->alertpipe[0], F_SETFL, flags | O_NONBLOCK);
00785          flags = fcntl(tmp->alertpipe[1], F_GETFL);
00786          fcntl(tmp->alertpipe[1], F_SETFL, flags | O_NONBLOCK);
00787       }
00788    } else   /* Make sure we've got it done right if they don't */
00789       tmp->alertpipe[0] = tmp->alertpipe[1] = -1;
00790 
00791    /* Always watch the alertpipe */
00792    tmp->fds[AST_ALERT_FD] = tmp->alertpipe[0];
00793    /* And timing pipe */
00794    tmp->fds[AST_TIMING_FD] = tmp->timingfd;
00795    ast_string_field_set(tmp, name, "**Unknown**");
00796 
00797    /* Initial state */
00798    tmp->_state = state;
00799 
00800    tmp->streamid = -1;
00801    
00802    tmp->fin = global_fin;
00803    tmp->fout = global_fout;
00804 
00805    if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) {
00806       ast_string_field_build(tmp, uniqueid, "%li.%d", (long) time(NULL), 
00807          ast_atomic_fetchadd_int(&uniqueint, 1));
00808    } else {
00809       ast_string_field_build(tmp, uniqueid, "%s-%li.%d", ast_config_AST_SYSTEM_NAME, 
00810          (long) time(NULL), ast_atomic_fetchadd_int(&uniqueint, 1));
00811    }
00812 
00813    tmp->cid.cid_name = ast_strdup(cid_name);
00814    tmp->cid.cid_num = ast_strdup(cid_num);
00815    
00816    if (!ast_strlen_zero(name_fmt)) {
00817       /* Almost every channel is calling this function, and setting the name via the ast_string_field_build() call.
00818        * And they all use slightly different formats for their name string.
00819        * This means, to set the name here, we have to accept variable args, and call the string_field_build from here.
00820        * This means, that the stringfields must have a routine that takes the va_lists directly, and 
00821        * uses them to build the string, instead of forming the va_lists internally from the vararg ... list.
00822        * This new function was written so this can be accomplished.
00823        */
00824       va_start(ap1, name_fmt);
00825       va_start(ap2, name_fmt);
00826       ast_string_field_build_va(tmp, name, name_fmt, ap1, ap2);
00827       va_end(ap1);
00828       va_end(ap2);
00829 
00830       /* and now, since the channel structure is built, and has its name, let's call the
00831        * manager event generator with this Newchannel event. This is the proper and correct
00832        * place to make this call, but you sure do have to pass a lot of data into this func
00833        * to do it here!
00834        */
00835       manager_event(EVENT_FLAG_CALL, "Newchannel",
00836                "Channel: %s\r\n"
00837                "State: %s\r\n"
00838                "CallerIDNum: %s\r\n"
00839                "CallerIDName: %s\r\n"
00840                "Uniqueid: %s\r\n",
00841                tmp->name, ast_state2str(state),
00842                S_OR(cid_num, "<unknown>"),
00843                S_OR(cid_name, "<unknown>"),
00844                tmp->uniqueid);
00845    }
00846 
00847    /* Reminder for the future: under what conditions do we NOT want to track cdrs on channels? */
00848 
00849    /* These 4 variables need to be set up for the cdr_init() to work right */
00850    if (amaflag)
00851       tmp->amaflags = amaflag;
00852    else
00853       tmp->amaflags = ast_default_amaflags;
00854    
00855    if (!ast_strlen_zero(acctcode))
00856       ast_string_field_set(tmp, accountcode, acctcode);
00857    else
00858       ast_string_field_set(tmp, accountcode, ast_default_accountcode);
00859       
00860    if (!ast_strlen_zero(context))
00861       ast_copy_string(tmp->context, context, sizeof(tmp->context));
00862    else
00863       strcpy(tmp->context, "default");
00864 
00865    if (!ast_strlen_zero(exten))
00866       ast_copy_string(tmp->exten, exten, sizeof(tmp->exten));
00867    else
00868       strcpy(tmp->exten, "s");
00869 
00870    tmp->priority = 1;
00871       
00872    tmp->cdr = ast_cdr_alloc();
00873    ast_cdr_init(tmp->cdr, tmp);
00874    ast_cdr_start(tmp->cdr);
00875    
00876    headp = &tmp->varshead;
00877    AST_LIST_HEAD_INIT_NOLOCK(headp);
00878    
00879    ast_mutex_init(&tmp->lock);
00880    
00881    AST_LIST_HEAD_INIT_NOLOCK(&tmp->datastores);
00882    
00883    ast_string_field_set(tmp, language, defaultlanguage);
00884 
00885    tmp->tech = &null_tech;
00886 
00887    AST_LIST_LOCK(&channels);
00888    AST_LIST_INSERT_HEAD(&channels, tmp, chan_list);
00889    AST_LIST_UNLOCK(&channels);
00890 
00891    return tmp;
00892 }

int 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

Parameters:
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 4062 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_strlen_zero(), ast_test_flag, ast_tvadd(), ast_tvsub(), ast_verbose(), ast_channel_tech::bridge, bridge_playfile(), ast_channel::cid, ast_callerid::cid_num, ast_bridge_config::end_sound, EVENT_FLAG_CALL, ast_bridge_config::feature_timer, ast_bridge_config::features_callee, ast_bridge_config::features_caller, ast_bridge_config::firstpass, ast_bridge_config::flags, ast_channel::generator, LOG_DEBUG, LOG_WARNING, manager_event(), ast_channel::monitor, ast_channel::nativeformats, option_debug, option_verbose, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), ast_bridge_config::play_warning, ast_channel::readformat, ast_channel_tech::send_digit_begin, ast_channel::spies, ast_bridge_config::start_sound, ast_bridge_config::start_time, t, ast_channel::tech, ast_bridge_config::timelimit, VERBOSE_PREFIX_3, ast_bridge_config::warning_freq, ast_bridge_config::warning_sound, and ast_channel::writeformat.

04064 {
04065    struct ast_channel *who = NULL;
04066    enum ast_bridge_result res = AST_BRIDGE_COMPLETE;
04067    int nativefailed=0;
04068    int firstpass;
04069    int o0nativeformats;
04070    int o1nativeformats;
04071    long time_left_ms=0;
04072    struct timeval nexteventts = { 0, };
04073    char caller_warning = 0;
04074    char callee_warning = 0;
04075 
04076    if (c0->_bridge) {
04077       ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
04078          c0->name, c0->_bridge->name);
04079       return -1;
04080    }
04081    if (c1->_bridge) {
04082       ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
04083          c1->name, c1->_bridge->name);
04084       return -1;
04085    }
04086    
04087    /* Stop if we're a zombie or need a soft hangup */
04088    if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
04089        ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1))
04090       return -1;
04091 
04092    *fo = NULL;
04093    firstpass = config->firstpass;
04094    config->firstpass = 0;
04095 
04096    if (ast_tvzero(config->start_time))
04097       config->start_time = ast_tvnow();
04098    time_left_ms = config->timelimit;
04099 
04100    caller_warning = ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING);
04101    callee_warning = ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING);
04102 
04103    if (config->start_sound && firstpass) {
04104       if (caller_warning)
04105          bridge_playfile(c0, c1, config->start_sound, time_left_ms / 1000);
04106       if (callee_warning)
04107          bridge_playfile(c1, c0, config->start_sound, time_left_ms / 1000);
04108    }
04109 
04110    /* Keep track of bridge */
04111    c0->_bridge = c1;
04112    c1->_bridge = c0;
04113 
04114    /* \todo  XXX here should check that cid_num is not NULL */
04115    manager_event(EVENT_FLAG_CALL, "Link",
04116             "Channel1: %s\r\n"
04117             "Channel2: %s\r\n"
04118             "Uniqueid1: %s\r\n"
04119             "Uniqueid2: %s\r\n"
04120             "CallerID1: %s\r\n"
04121             "CallerID2: %s\r\n",
04122             c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num);
04123 
04124    o0nativeformats = c0->nativeformats;
04125    o1nativeformats = c1->nativeformats;
04126 
04127    if (config->feature_timer) {
04128       nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->feature_timer, 1000));
04129    } else if (config->timelimit) {
04130       nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000));
04131       if (caller_warning || callee_warning)
04132          nexteventts = ast_tvsub(nexteventts, ast_samp2tv(config->play_warning, 1000));
04133    }
04134 
04135    if (!c0->tech->send_digit_begin)
04136       ast_set_flag(c1, AST_FLAG_END_DTMF_ONLY);
04137    if (!c1->tech->send_digit_begin)
04138       ast_set_flag(c0, AST_FLAG_END_DTMF_ONLY);
04139 
04140    for (/* ever */;;) {
04141       struct timeval now = { 0, };
04142       int to;
04143 
04144       to = -1;
04145 
04146       if (!ast_tvzero(nexteventts)) {
04147          now = ast_tvnow();
04148          to = ast_tvdiff_ms(nexteventts, now);
04149          if (to <= 0) {
04150             if (!config->timelimit) {
04151                res = AST_BRIDGE_COMPLETE;
04152                break;
04153             }
04154             to = 0;
04155          }
04156       }
04157 
04158       if (config->timelimit) {
04159          time_left_ms = config->timelimit - ast_tvdiff_ms(now, config->start_time);
04160          if (time_left_ms < to)
04161             to = time_left_ms;
04162 
04163          if (time_left_ms <= 0) {
04164             if (caller_warning && config->end_sound)
04165                bridge_playfile(c0, c1, config->end_sound, 0);
04166             if (callee_warning && config->end_sound)
04167                bridge_playfile(c1, c0, config->end_sound, 0);
04168             *fo = NULL;
04169             if (who)
04170                *rc = who;
04171             res = 0;
04172             break;
04173          }
04174          
04175          if (!to) {
04176             if (time_left_ms >= 5000 && config->warning_sound && config->play_warning) {
04177                int t = (time_left_ms + 500) / 1000; /* round to nearest second */
04178                if (caller_warning)
04179                   bridge_playfile(c0, c1, config->warning_sound, t);
04180                if (callee_warning)
04181                   bridge_playfile(c1, c0, config->warning_sound, t);
04182             }
04183             if (config->warning_freq && (time_left_ms > (config->warning_freq + 5000)))
04184                nexteventts = ast_tvadd(nexteventts, ast_samp2tv(config->warning_freq, 1000));
04185             else
04186                nexteventts = ast_tvadd(config->start_time, ast_samp2tv(config->timelimit, 1000));
04187          }
04188       }
04189 
04190       if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE) {
04191          if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
04192             c0->_softhangup = 0;
04193          if (c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
04194             c1->_softhangup = 0;
04195          c0->_bridge = c1;
04196          c1->_bridge = c0;
04197          if (option_debug)
04198             ast_log(LOG_DEBUG, "Unbridge signal received. Ending native bridge.\n");
04199          continue;
04200       }
04201       
04202       /* Stop if we're a zombie or need a soft hangup */
04203       if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) ||
04204           ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) {
04205          *fo = NULL;
04206          if (who)
04207             *rc = who;
04208          res = 0;
04209          if (option_debug)
04210             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",
04211                c0->name, c1->name,
04212                ast_test_flag(c0, AST_FLAG_ZOMBIE) ? "Yes" : "No",
04213                ast_check_hangup(c0) ? "Yes" : "No",
04214                ast_test_flag(c1, AST_FLAG_ZOMBIE) ? "Yes" : "No",
04215                ast_check_hangup(c1) ? "Yes" : "No");
04216          break;
04217       }
04218       
04219       /* See if the BRIDGEPEER variable needs to be updated */
04220       if (!ast_strlen_zero(pbx_builtin_getvar_helper(c0, "BRIDGEPEER")))
04221          pbx_builtin_setvar_helper(c0, "BRIDGEPEER", c1->name);
04222       if (!ast_strlen_zero(pbx_builtin_getvar_helper(c1, "BRIDGEPEER")))
04223          pbx_builtin_setvar_helper(c1, "BRIDGEPEER", c0->name);
04224       
04225       if (c0->tech->bridge &&
04226           (config->timelimit == 0) &&
04227           (c0->tech->bridge == c1->tech->bridge) &&
04228           !nativefailed && !c0->monitor && !c1->monitor &&
04229           !c0->spies && !c1->spies && !ast_test_flag(&(config->features_callee),AST_FEATURE_REDIRECT) &&
04230           !ast_test_flag(&(config->features_caller),AST_FEATURE_REDIRECT) ) {
04231          /* Looks like they share a bridge method and nothing else is in the way */
04232          ast_set_flag(c0, AST_FLAG_NBRIDGE);
04233          ast_set_flag(c1, AST_FLAG_NBRIDGE);
04234          if ((res = c0->tech->bridge(c0, c1, config->flags, fo, rc, to)) == AST_BRIDGE_COMPLETE) {
04235             /* \todo  XXX here should check that cid_num is not NULL */
04236             manager_event(EVENT_FLAG_CALL, "Unlink",
04237                      "Channel1: %s\r\n"
04238                      "Channel2: %s\r\n"
04239                      "Uniqueid1: %s\r\n"
04240                      "Uniqueid2: %s\r\n"
04241                      "CallerID1: %s\r\n"
04242                      "CallerID2: %s\r\n",
04243                      c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num);
04244             if (option_debug)
04245                ast_log(LOG_DEBUG, "Returning from native bridge, channels: %s, %s\n", c0->name, c1->name);
04246 
04247             ast_clear_flag(c0, AST_FLAG_NBRIDGE);
04248             ast_clear_flag(c1, AST_FLAG_NBRIDGE);
04249 
04250             if (c0->_softhangup == AST_SOFTHANGUP_UNBRIDGE || c1->_softhangup == AST_SOFTHANGUP_UNBRIDGE)
04251                continue;
04252 
04253             c0->_bridge = NULL;
04254             c1->_bridge = NULL;
04255 
04256             return res;
04257          } else {
04258             ast_clear_flag(c0, AST_FLAG_NBRIDGE);
04259             ast_clear_flag(c1, AST_FLAG_NBRIDGE);
04260          }
04261          switch (res) {
04262          case AST_BRIDGE_RETRY:
04263             continue;
04264          default:
04265             if (option_verbose > 2)
04266                ast_verbose(VERBOSE_PREFIX_3 "Native bridging %s and %s ended\n",
04267                       c0->name, c1->name);
04268             /* fallthrough */
04269          case AST_BRIDGE_FAILED_NOWARN:
04270             nativefailed++;
04271             break;
04272          }
04273       }
04274    
04275       if (((c0->writeformat != c1->readformat) || (c0->readformat != c1->writeformat) ||
04276           (c0->nativeformats != o0nativeformats) || (c1->nativeformats != o1nativeformats)) &&
04277           !(c0->generator || c1->generator)) {
04278          if (ast_channel_make_compatible(c0, c1)) {
04279             ast_log(LOG_WARNING, "Can't make %s and %s compatible\n", c0->name, c1->name);
04280             /* \todo  XXX here should check that cid_num is not NULL */
04281                                 manager_event(EVENT_FLAG_CALL, "Unlink",
04282                      "Channel1: %s\r\n"
04283                      "Channel2: %s\r\n"
04284                      "Uniqueid1: %s\r\n"
04285                      "Uniqueid2: %s\r\n"
04286                      "CallerID1: %s\r\n"
04287                      "CallerID2: %s\r\n",
04288                      c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num);
04289             return AST_BRIDGE_FAILED;
04290          }
04291          o0nativeformats = c0->nativeformats;
04292          o1nativeformats = c1->nativeformats;
04293       }
04294       res = ast_generic_bridge(c0, c1, config, fo, rc, nexteventts);
04295       if (res != AST_BRIDGE_RETRY)
04296          break;
04297    }
04298 
04299    ast_clear_flag(c0, AST_FLAG_END_DTMF_ONLY);
04300    ast_clear_flag(c1, AST_FLAG_END_DTMF_ONLY);
04301 
04302    c0->_bridge = NULL;
04303    c1->_bridge = NULL;
04304 
04305    /* \todo  XXX here should check that cid_num is not NULL */
04306    manager_event(EVENT_FLAG_CALL, "Unlink",
04307             "Channel1: %s\r\n"
04308             "Channel2: %s\r\n"
04309             "Uniqueid1: %s\r\n"
04310             "Uniqueid2: %s\r\n"
04311             "CallerID1: %s\r\n"
04312             "CallerID2: %s\r\n",
04313             c0->name, c1->name, c0->uniqueid, c1->uniqueid, c0->cid.cid_num, c1->cid.cid_num);
04314    if (option_debug)
04315       ast_log(LOG_DEBUG, "Bridge stops bridging channels %s and %s\n", c0->name, c1->name);
04316 
04317    return res;
04318 }

int ast_channel_cmpwhentohangup ( struct ast_channel chan,
time_t  offset 
)

Compare a offset with the settings of when to hang a channel up.

Parameters:
chan channel on which to check for hang up
offset offset in seconds from current time
Returns:
1, 0, or -1 This function compares a offset from current time with the absolute time out on a channel (when to hang up). If the absolute time out on a channel is earlier than current time plus the offset, it returns 1, if the two time values are equal, it return 0, otherwise, it retturn -1.

Definition at line 494 of file channel.c.

References ast_channel::whentohangup.

00495 {
00496    time_t whentohangup;
00497 
00498    if (chan->whentohangup == 0) {
00499       return (offset == 0) ? 0 : -1;
00500    } else {
00501       if (offset == 0)  /* XXX why is this special ? */
00502          return (1);
00503       else {
00504          whentohangup = offset + time (NULL);
00505          if (chan->whentohangup < whentohangup)
00506             return (1);
00507          else if (chan->whentohangup == whentohangup)
00508             return (0);
00509          else
00510             return (-1);
00511       }
00512    }
00513 }

int ast_channel_datastore_add ( struct ast_channel chan,
struct ast_datastore datastore 
)

Add a datastore to a channel.

Definition at line 1319 of file channel.c.

References AST_LIST_INSERT_HEAD.

01320 {
01321    int res = 0;
01322 
01323    AST_LIST_INSERT_HEAD(&chan->datastores, datastore, entry);
01324 
01325    return res;
01326 }

struct ast_datastore* ast_channel_datastore_alloc ( const struct ast_datastore_info info,
char *  uid 
) [read]

Create a channel datastore structure.

Definition at line 1275 of file channel.c.

References ast_calloc, ast_strdup, ast_datastore::info, and ast_datastore::uid.

01276 {
01277    struct ast_datastore *datastore = NULL;
01278 
01279    /* Make sure we at least have type so we can identify this */
01280    if (info == NULL) {
01281       return NULL;
01282    }
01283 
01284    /* Allocate memory for datastore and clear it */
01285    datastore = ast_calloc(1, sizeof(*datastore));
01286    if (datastore == NULL) {
01287       return NULL;
01288    }
01289 
01290    datastore->info = info;
01291 
01292    datastore->uid = ast_strdup(uid);
01293 
01294    return datastore;
01295 }

struct ast_datastore* ast_channel_datastore_find ( struct ast_channel chan,
const struct ast_datastore_info info,
char *  uid 
) [read]

Find a datastore on a channel.

Definition at line 1346 of file channel.c.

References AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_datastore::info, and ast_datastore::uid.

01347 {
01348    struct ast_datastore *datastore = NULL;
01349    
01350    if (info == NULL)
01351       return NULL;
01352 
01353    AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore, entry) {
01354       if (datastore->info == info) {
01355          if (uid != NULL && datastore->uid != NULL) {
01356             if (!strcasecmp(uid, datastore->uid)) {
01357                /* Matched by type AND uid */
01358                break;
01359             }
01360          } else {
01361             /* Matched by type at least */
01362             break;
01363          }
01364       }
01365    }
01366    AST_LIST_TRAVERSE_SAFE_END
01367 
01368    return datastore;
01369 }

int ast_channel_datastore_free ( struct ast_datastore datastore  ) 

Free a channel datastore structure.

Definition at line 1297 of file channel.c.

References ast_datastore::data, ast_datastore_info::destroy, free, ast_datastore::info, and ast_datastore::uid.

01298 {
01299    int res = 0;
01300 
01301    /* Using the destroy function (if present) destroy the data */
01302    if (datastore->info->destroy != NULL && datastore->data != NULL) {
01303       datastore->info->destroy(datastore->data);
01304       datastore->data = NULL;
01305    }
01306 
01307    /* Free allocated UID memory */
01308    if (datastore->uid != NULL) {
01309       free(datastore->uid);
01310       datastore->uid = NULL;
01311    }
01312 
01313    /* Finally free memory used by ourselves */
01314    free(datastore);
01315 
01316    return res;
01317 }

int ast_channel_datastore_remove ( struct ast_channel chan,
struct ast_datastore datastore 
)

Remove a datastore from a channel.

Definition at line 1328 of file channel.c.

References AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, and AST_LIST_TRAVERSE_SAFE_END.

01329 {
01330    struct ast_datastore *datastore2 = NULL;
01331    int res = -1;
01332 
01333    /* Find our position and remove ourselves */
01334    AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, datastore2, entry) {
01335       if (datastore2 == datastore) {
01336          AST_LIST_REMOVE_CURRENT(&chan->datastores, entry);
01337          res = 0;
01338          break;
01339       }
01340    }
01341    AST_LIST_TRAVERSE_SAFE_END
01342 
01343    return res;
01344 }

int ast_channel_defer_dtmf ( struct ast_channel chan  ) 

Set defer DTMF flag on channel.

Defers DTMF

Defer DTMF so that you only read things like hangups and audio. Returns non-zero if channel was already DTMF-deferred or 0 if channel is just now being DTMF-deferred

Definition at line 986 of file channel.c.

References AST_FLAG_DEFER_DTMF, ast_set_flag, and ast_test_flag.

00987 {
00988    int pre = 0;
00989 
00990    if (chan) {
00991       pre = ast_test_flag(chan, AST_FLAG_DEFER_DTMF);
00992       ast_set_flag(chan, AST_FLAG_DEFER_DTMF);
00993    }
00994    return pre;
00995 }

void ast_channel_free ( struct ast_channel  ) 

Free a channel structure.

Definition at line 1190 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_ERROR, 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.

01191 {
01192    int fd;
01193    struct ast_var_t *vardata;
01194    struct ast_frame *f;
01195    struct varshead *headp;
01196    struct ast_datastore *datastore = NULL;
01197    char name[AST_CHANNEL_NAME];
01198    
01199    headp=&chan->varshead;
01200    
01201    AST_LIST_LOCK(&channels);
01202    if (!AST_LIST_REMOVE(&channels, chan, chan_list)) {
01203       AST_LIST_UNLOCK(&channels);
01204       ast_log(LOG_ERROR, "Unable to find channel in list to free. Assuming it has already been done.\n");
01205    }
01206    /* Lock and unlock the channel just to be sure nobody
01207       has it locked still */
01208    ast_channel_lock(chan);
01209    ast_channel_unlock(chan);
01210    if (chan->tech_pvt) {
01211       ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name);
01212       free(chan->tech_pvt);
01213    }
01214 
01215    if (chan->sched)
01216       sched_context_destroy(chan->sched);
01217 
01218    ast_copy_string(name, chan->name, sizeof(name));
01219 
01220    /* Stop monitoring */
01221    if (chan->monitor)
01222       chan->monitor->stop( chan, 0 );
01223 
01224    /* If there is native format music-on-hold state, free it */
01225    if (chan->music_state)
01226       ast_moh_cleanup(chan);
01227 
01228    /* if someone is whispering on the channel, stop them */
01229    if (chan->whisper)
01230       ast_channel_whisper_stop(chan);
01231 
01232    /* Free translators */
01233    if (chan->readtrans)
01234       ast_translator_free_path(chan->readtrans);
01235    if (chan->writetrans)
01236       ast_translator_free_path(chan->writetrans);
01237    if (chan->pbx)
01238       ast_log(LOG_WARNING, "PBX may not have been terminated properly on '%s'\n", chan->name);
01239    free_cid(&chan->cid);
01240    ast_mutex_destroy(&chan->lock);
01241    /* Close pipes if appropriate */
01242    if ((fd = chan->alertpipe[0]) > -1)
01243       close(fd);
01244    if ((fd = chan->alertpipe[1]) > -1)
01245       close(fd);
01246    if ((fd = chan->timingfd) > -1)
01247       close(fd);
01248    while ((f = AST_LIST_REMOVE_HEAD(&chan->readq, frame_list)))
01249       ast_frfree(f);
01250    
01251    /* Get rid of each of the data stores on the channel */
01252    while ((datastore = AST_LIST_REMOVE_HEAD(&chan->datastores, entry)))
01253       /* Free the data store */
01254       ast_channel_datastore_free(datastore);
01255    AST_LIST_HEAD_INIT_NOLOCK(&chan->datastores);
01256 
01257    /* loop over the variables list, freeing all data and deleting list items */
01258    /* no need to lock the list, as the channel is already locked */
01259    
01260    while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries)))
01261       ast_var_delete(vardata);
01262 
01263    ast_app_group_discard(chan);
01264 
01265    /* Destroy the jitterbuffer */
01266    ast_jb_destroy(chan);
01267 
01268    ast_string_field_free_pools(chan);
01269    free(chan);
01270    AST_LIST_UNLOCK(&channels);
01271 
01272    ast_device_state_changed_literal(name);
01273 }

void ast_channel_inherit_variables ( const struct ast_channel parent,
struct ast_channel child 
)

Inherits channel variable from parent to child channel.

Parameters:
parent Parent channel
child Child channel
Scans all channel variables in the parent channel, looking for those that should be copied into the child channel. Variables whose names begin with a single '_' are copied into the child channel with the prefix removed. Variables whose names begin with '__' are copied into the child channel with their names unchanged.

Definition at line 3454 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.

03455 {
03456    struct ast_var_t *current, *newvar;
03457    const char *varname;
03458 
03459    AST_LIST_TRAVERSE(&parent->varshead, current, entries) {
03460       int vartype = 0;
03461 
03462       varname = ast_var_full_name(current);
03463       if (!varname)
03464          continue;
03465 
03466       if (varname[0] == '_') {
03467          vartype = 1;
03468          if (varname[1] == '_')
03469             vartype = 2;
03470       }
03471 
03472       switch (vartype) {
03473       case 1:
03474          newvar = ast_var_assign(&varname[1], ast_var_value(current));
03475          if (newvar) {
03476             AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries);
03477             if (option_debug)
03478                ast_log(LOG_DEBUG, "Copying soft-transferable variable %s.\n", ast_var_name(newvar));
03479          }
03480          break;
03481       case 2:
03482          newvar = ast_var_assign(ast_var_full_name(current), ast_var_value(current));
03483          if (newvar) {
03484             AST_LIST_INSERT_TAIL(&child->varshead, newvar, entries);
03485             if (option_debug)
03486                ast_log(LOG_DEBUG, "Copying hard-transferable variable %s.\n", ast_var_name(newvar));
03487          }
03488          break;
03489       default:
03490          if (option_debug)
03491             ast_log(LOG_DEBUG, "Not copying variable %s.\n", ast_var_name(current));
03492          break;
03493       }
03494    }
03495 }

int ast_channel_make_compatible ( struct ast_channel c0,
struct ast_channel c1 
)

Makes two channel formats compatible.

Parameters:
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 .
Returns:
Returns 0 on success and -1 if it could not be done

Definition at line 3323 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, ast_channel::nativeformats, ast_channel::readformat, and ast_channel::writeformat.

03324 {
03325    int src;
03326    int dst;
03327 
03328    if (chan->readformat == peer->writeformat && chan->writeformat == peer->readformat) {
03329       /* Already compatible!  Moving on ... */
03330       return 0;
03331    }
03332 
03333    /* Set up translation from the chan to the peer */
03334    src = chan->nativeformats;
03335    dst = peer->nativeformats;
03336    if (ast_translator_best_choice(&dst, &src) < 0) {
03337       ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", chan->name, src, peer->name, dst);
03338       return -1;
03339    }
03340 
03341    /* if the best path is not 'pass through', then
03342       transcoding is needed; if desired, force transcode path
03343       to use SLINEAR between channels, but only if there is
03344       no direct conversion available */
03345    if ((src != dst) && ast_opt_transcode_via_slin &&
03346        (ast_translate_path_steps(dst, src) != 1))
03347       dst = AST_FORMAT_SLINEAR;
03348    if (ast_set_read_format(chan, dst) < 0) {
03349       ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", chan->name, dst);
03350       return -1;
03351    }
03352    if (ast_set_write_format(peer, dst) < 0) {
03353       ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", peer->name, dst);
03354       return -1;
03355    }
03356 
03357    /* Set up translation from the peer to the chan */
03358    src = peer->nativeformats;
03359    dst = chan->nativeformats;
03360    if (ast_translator_best_choice(&dst, &src) < 0) {
03361       ast_log(LOG_WARNING, "No path to translate from %s(%d) to %s(%d)\n", peer->name, src, chan->name, dst);
03362       return -1;
03363    }
03364 
03365    /* if the best path is not 'pass through', then
03366       transcoding is needed; if desired, force transcode path
03367       to use SLINEAR between channels, but only if there is
03368       no direct conversion available */
03369    if ((src != dst) && ast_opt_transcode_via_slin &&
03370        (ast_translate_path_steps(dst, src) != 1))
03371       dst = AST_FORMAT_SLINEAR;
03372    if (ast_set_read_format(peer, dst) < 0) {
03373       ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", peer->name, dst);
03374       return -1;
03375    }
03376    if (ast_set_write_format(chan, dst) < 0) {
03377       ast_log(LOG_WARNING, "Unable to set write format on channel %s to %d\n", chan->name, dst);
03378       return -1;
03379    }
03380    return 0;
03381 }

int ast_channel_masquerade ( struct ast_channel original,
struct ast_channel clone 
)

Weird function made for call transfers.

Parameters:
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 3383 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.

03384 {
03385    int res = -1;
03386    struct ast_channel *final_orig = original, *final_clone = clone;
03387 
03388    ast_channel_lock(original);
03389    while (ast_channel_trylock(clone)) {
03390       ast_channel_unlock(original);
03391       usleep(1);
03392       ast_channel_lock(original);
03393    }
03394 
03395    /* each of these channels may be sitting behind a channel proxy (i.e. chan_agent)
03396       and if so, we don't really want to masquerade it, but its proxy */
03397    if (original->_bridge && (original->_bridge != ast_bridged_channel(original)) && (original->_bridge->_bridge != original))
03398       final_orig = original->_bridge;
03399 
03400    if (clone->_bridge && (clone->_bridge != ast_bridged_channel(clone)) && (clone->_bridge->_bridge != clone))
03401       final_clone = clone->_bridge;
03402 
03403    if ((final_orig != original) || (final_clone != clone)) {
03404       ast_channel_lock(final_orig);
03405       while (ast_channel_trylock(final_clone)) {
03406          ast_channel_unlock(final_orig);
03407          usleep(1);
03408          ast_channel_lock(final_orig);
03409       }
03410       ast_channel_unlock(clone);
03411       ast_channel_unlock(original);
03412       original = final_orig;
03413       clone = final_clone;
03414    }
03415 
03416    if (original == clone) {
03417       ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name);
03418       ast_channel_unlock(clone);
03419       ast_channel_unlock(original);
03420       return -1;
03421    }
03422 
03423    if (option_debug)
03424       ast_log(LOG_DEBUG, "Planning to masquerade channel %s into the structure of %s\n",
03425          clone->name, original->name);
03426    if (original->masq) {
03427       ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
03428          original->masq->name, original->name);
03429    } else if (clone->masqr) {
03430       ast_log(LOG_WARNING, "%s is already going to masquerade as %s\n",
03431          clone->name, clone->masqr->name);
03432    } else {
03433       original->masq = clone;
03434       clone->masqr = original;
03435       ast_queue_frame(original, &ast_null_frame);
03436       ast_queue_frame(clone, &ast_null_frame);
03437       if (option_debug)
03438          ast_log(LOG_DEBUG, "Done planning to masquerade channel %s into the structure of %s\n", clone->name, original->name);
03439       res = 0;
03440    }
03441 
03442    ast_channel_unlock(clone);
03443    ast_channel_unlock(original);
03444 
03445    return res;
03446 }

struct ast_frame* ast_channel_queryoption ( struct ast_channel channel,
int  option,
void *  data,
int *  datalen,
int  block 
) [read]

Checks the value of an option

Query the value of an option, optionally blocking until a reply is received Works similarly to setoption except only reads the options.

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.

Parameters:
tech Structure defining channel technology or "type"
Returns:
Returns 0 on success, -1 on failure.

Definition at line 516 of file channel.c.

References ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_verbose(), ast_channel_tech::description, LOG_DEBUG, LOG_WARNING, option_debug, option_verbose, chanlist::tech, ast_channel_tech::type, and VERBOSE_PREFIX_2.

00517 {
00518    struct chanlist *chan;
00519 
00520    AST_LIST_LOCK(&channels);
00521 
00522    AST_LIST_TRAVERSE(&backends, chan, list) {
00523       if (!strcasecmp(tech->type, chan->tech->type)) {
00524          ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type);
00525          AST_LIST_UNLOCK(&channels);
00526          return -1;
00527       }
00528    }
00529    
00530    if (!(chan = ast_calloc(1, sizeof(*chan)))) {
00531       AST_LIST_UNLOCK(&channels);
00532       return -1;
00533    }
00534    chan->tech = tech;
00535    AST_LIST_INSERT_HEAD(&backends, chan, list);
00536 
00537    if (option_debug)
00538       ast_log(LOG_DEBUG, "Registered handler for '%s' (%s)\n", chan->tech->type, chan->tech->description);
00539 
00540    if (option_verbose > 1)
00541       ast_verbose(VERBOSE_PREFIX_2 "Registered channel type '%s' (%s)\n", chan->tech->type,
00542              chan->tech->description);
00543 
00544    AST_LIST_UNLOCK(&channels);
00545    return 0;
00546 }

int ast_channel_sendhtml ( struct ast_channel channel,
int  subclass,
const char *  data,
int  datalen 
)

Sends HTML on given channel

Send HTML or URL on link. Returns 0 on success or -1 on failure

Definition at line 3311 of file channel.c.

References ast_channel_tech::send_html, and ast_channel::tech.

03312 {
03313    if (chan->tech->send_html)
03314       return chan->tech->send_html(chan, subclass, data, datalen);
03315    return -1;
03316 }

int ast_channel_sendurl ( struct ast_channel channel,
const char *  url 
)

Sends a URL on a given link

Send URL on link. Returns 0 on success or -1 on failure

Definition at line 3318 of file channel.c.

References ast_channel_sendhtml(), and AST_HTML_URL.

03319 {
03320    return ast_channel_sendhtml(chan, AST_HTML_URL, url, strlen(url) + 1);
03321 }

int ast_channel_setoption ( struct ast_channel channel,
int  option,
void *  data,
int  datalen,
int  block 
)

Sets an option on a channel.

Sets an option on a channel

Parameters:
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 4321 of file channel.c.

References ast_log(), LOG_ERROR, ast_channel_tech::setoption, and ast_channel::tech.

04322 {
04323    int res;
04324 
04325    if (chan->tech->setoption) {
04326       res = chan->tech->setoption(chan, option, data, datalen);
04327       if (res < 0)
04328          return res;
04329    } else {
04330       errno = ENOSYS;
04331       return -1;
04332    }
04333    if (block) {
04334       /* XXX Implement blocking -- just wait for our option frame reply, discarding
04335          intermediate packets. XXX */
04336       ast_log(LOG_ERROR, "XXX Blocking not implemented yet XXX\n");
04337       return -1;
04338    }
04339    return 0;
04340 }

void ast_channel_setwhentohangup ( struct ast_channel chan,
time_t  offset 
)

Set when to hang a channel up.

Parameters:
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 486 of file channel.c.

References ast_null_frame, ast_queue_frame(), and ast_channel::whentohangup.

00487 {
00488    chan->whentohangup = offset ? time(NULL) + offset : 0;
00489    ast_queue_frame(chan, &ast_null_frame);
00490    return;
00491 }

struct ast_silence_generator* ast_channel_start_silence_generator ( struct ast_channel chan  )  [read]

Starts a silence generator on the given channel.

Parameters:
chan The channel to generate silence on
Returns:
An ast_silence_generator pointer, or NULL if an error occurs
This function will cause SLINEAR silence to be generated on the supplied channel until it is disabled; if the channel cannot be put into SLINEAR mode then the function will fail.

The pointer returned by this function must be preserved and passed to ast_channel_stop_silence_generator when you wish to stop the silence generation.

Definition at line 4769 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, option_debug, and ast_channel::writeformat.

04770 {
04771    struct ast_silence_generator *state;
04772 
04773    if (!(state = ast_calloc(1, sizeof(*state)))) {
04774       return NULL;
04775    }
04776 
04777    state->old_write_format = chan->writeformat;
04778 
04779    if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
04780       ast_log(LOG_ERROR, "Could not set write format to SLINEAR\n");
04781       free(state);
04782       return NULL;
04783    }
04784 
04785    ast_activate_generator(chan, &silence_generator, state);
04786 
04787    if (option_debug)
04788       ast_log(LOG_DEBUG, "Started silence generator on '%s'\n", chan->name);
04789 
04790    return state;
04791 }

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.

Parameters:
chan The channel to operate on
state The ast_silence_generator pointer return by a previous call to ast_channel_start_silence_generator.
Returns:
nothing
This function will stop the operating silence generator and return the channel to its previous write format.

Definition at line 4793 of file channel.c.

References ast_deactivate_generator(), ast_log(), ast_set_write_format(), free, LOG_DEBUG, LOG_ERROR, ast_silence_generator::old_write_format, and option_debug.

04794 {
04795    if (!state)
04796       return;
04797 
04798    ast_deactivate_generator(chan);
04799 
04800    if (option_debug)
04801       ast_log(LOG_DEBUG, "Stopped silence generator on '%s'\n", chan->name);
04802 
04803    if (ast_set_write_format(chan, state->old_write_format) < 0)
04804       ast_log(LOG_ERROR, "Could not return write format to its original state\n");
04805 
04806    free(state);
04807 }

int ast_channel_supports_html ( struct ast_channel channel  ) 

Checks for HTML support on a channel

Returns 0 if channel does not support HTML or non-zero if it does

Definition at line 3306 of file channel.c.

References ast_channel_tech::send_html, and ast_channel::tech.

03307 {
03308    return (chan->tech->send_html) ? 1 : 0;
03309 }

void ast_channel_undefer_dtmf ( struct ast_channel chan  ) 

Unset defer DTMF flag on channel.

Undeos a defer

Undo defer. ast_read will return any dtmf characters that were queued

Definition at line 998 of file channel.c.

References ast_clear_flag, and AST_FLAG_DEFER_DTMF.

00999 {
01000    if (chan)
01001       ast_clear_flag(chan, AST_FLAG_DEFER_DTMF);
01002 }

void ast_channel_unregister ( const struct ast_channel_tech tech  ) 

Unregister a channel technology.

Parameters:
tech Structure defining channel technology or "type" that was previously registered
Returns:
No return value.

Definition at line 548 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.

00549 {
00550    struct chanlist *chan;
00551 
00552    if (option_debug)
00553       ast_log(LOG_DEBUG, "Unregistering channel type '%s'\n", tech->type);
00554 
00555    AST_LIST_LOCK(&channels);
00556 
00557    AST_LIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) {
00558       if (chan->tech == tech) {
00559          AST_LIST_REMOVE_CURRENT(&backends, list);
00560          free(chan);
00561          if (option_verbose > 1)
00562             ast_verbose(VERBOSE_PREFIX_2 "Unregistered channel type '%s'\n", tech->type);
00563          break;   
00564       }
00565    }
00566    AST_LIST_TRAVERSE_SAFE_END
00567 
00568    AST_LIST_UNLOCK(&channels);
00569 }

struct ast_channel* ast_channel_walk_locked ( const struct ast_channel prev  )  [read]

Browse channels in use Browse the channels currently in use.

Parameters:
prev where you want to start in the channel list
Returns:
Returns the next channel in the list, NULL on end. If it returns a channel, that channel *has been locked*!

Definition at line 1111 of file channel.c.

References channel_find_locked().

01112 {
01113    return channel_find_locked(prev, NULL, 0, NULL, NULL);
01114 }

int ast_channel_whisper_feed ( struct ast_channel chan,
struct ast_frame f 
)

Feed an audio frame into the whisper buffer on a channel.

Parameters:
chan The channel to whisper onto
f The frame to to whisper onto chan
Returns:
0 for success, non-zero for failure

Definition at line 5007 of file channel.c.

References ast_mutex_lock(), ast_mutex_unlock(), ast_slinfactory_feed(), ast_channel_whisper_buffer::lock, ast_channel_whisper_buffer::sf, and ast_channel::whisper.

05008 {
05009    if (!chan->whisper)
05010       return -1;
05011 
05012    ast_mutex_lock(&chan->whisper->lock);
05013    ast_slinfactory_feed(&chan->whisper->sf, f);
05014    ast_mutex_unlock(&chan->whisper->lock);
05015 
05016    return 0;
05017 }

int ast_channel_whisper_start ( struct ast_channel chan  ) 

Begin 'whispering' onto a channel.

Parameters:
chan The channel to whisper onto
Returns:
0 for success, non-zero for failure
This function will add a whisper buffer onto a channel and set a flag causing writes to the channel to reduce the volume level of the written audio samples, and then to mix in audio from the whisper buffer if it is available.

Note: This function performs no locking; you must hold the channel's lock before calling this function.

Definition at line 4992 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.

04993 {
04994    if (chan->whisper)
04995       return -1;
04996 
04997    if (!(chan->whisper = ast_calloc(1, sizeof(*chan->whisper))))
04998       return -1;
04999 
05000    ast_mutex_init(&chan->whisper->lock);
05001    ast_slinfactory_init(&chan->whisper->sf);
05002    ast_set_flag(chan, AST_FLAG_WHISPER);
05003 
05004    return 0;
05005 }

void ast_channel_whisper_stop ( struct ast_channel chan  ) 

Stop 'whispering' onto a channel.

Parameters:
chan The channel to whisper onto
Returns:
0 for success, non-zero for failure
Note: This function performs no locking; you must hold the channel's lock before calling this function.

Definition at line 5019 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::lock, ast_channel_whisper_buffer::original_format, ast_channel_whisper_buffer::path, ast_channel_whisper_buffer::sf, ast_channel::whisper, and ast_channel::writeformat.

05020 {
05021    if (!chan->whisper)
05022       return;
05023 
05024    ast_clear_flag(chan, AST_FLAG_WHISPER);
05025    if (chan->whisper->path)
05026       ast_translator_free_path(chan->whisper->path);
05027    if (chan->whisper->original_format && chan->writeformat == AST_FORMAT_SLINEAR)
05028       ast_set_write_format(chan, chan->whisper->original_format);
05029    ast_slinfactory_destroy(&chan->whisper->sf);
05030    ast_mutex_destroy(&chan->whisper->lock);
05031    free(chan->whisper);
05032    chan->whisper = NULL;
05033 }

struct ast_variable* ast_channeltype_list ( void   )  [read]

return an ast_variable list of channeltypes

Definition at line 182 of file channel.c.

References AST_LIST_TRAVERSE, ast_variable_new(), ast_channel_tech::description, chanlist::tech, ast_channel_tech::type, and var.

00183 {
00184    struct chanlist *cl;
00185    struct ast_variable *var=NULL, *prev = NULL;
00186    AST_LIST_TRAVERSE(&backends, cl, list) {
00187       if (prev)  {
00188          if ((prev->next = ast_variable_new(cl->tech->type, cl->tech->description)))
00189             prev = prev->next;
00190       } else {
00191          var = ast_variable_new(cl->tech->type, cl->tech->description);
00192          prev = var;
00193       }
00194    }
00195    return var;
00196 }

int ast_check_hangup ( struct ast_channel chan  ) 

Check to see if a channel is needing hang up.

Parameters:
chan channel on which to check for hang up This function determines if the channel is being requested to be hung up.
Returns:
Returns 0 if not, or 1 if hang up is requested (including time-out).

Definition at line 404 of file channel.c.

References ast_channel::_softhangup, AST_SOFTHANGUP_TIMEOUT, ast_channel::tech_pvt, and ast_channel::whentohangup.

00405 {
00406    if (chan->_softhangup)     /* yes if soft hangup flag set */
00407       return 1;
00408    if (!chan->tech_pvt)    /* yes if no technology private data */
00409       return 1;
00410    if (!chan->whentohangup)   /* no if no hangup scheduled */
00411       return 0;
00412    if (chan->whentohangup > time(NULL))   /* no if hangup time has not come yet. */
00413       return 0;
00414    chan->_softhangup |= AST_SOFTHANGUP_TIMEOUT; /* record event */
00415    return 1;
00416 }

void ast_deactivate_generator ( struct ast_channel chan  ) 

Deactive an active generator

Definition at line 1823 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.

01824 {
01825    ast_channel_lock(chan);
01826    if (chan->generatordata) {
01827       if (chan->generator && chan->generator->release)
01828          chan->generator->release(chan, chan->generatordata);
01829       chan->generatordata = NULL;
01830       chan->generator = NULL;
01831       chan->fds[AST_GENERATOR_FD] = -1;
01832       ast_clear_flag(chan, AST_FLAG_WRITE_INT);
01833       ast_settimeout(chan, 0, NULL, NULL);
01834    }
01835    ast_channel_unlock(chan);
01836 }

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.

Parameters:
chan Channel to masquerade
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.

Note:
Assumes channel will be locked when called

Definition at line 3529 of file channel.c.

References ast_channel::_softhangup, ast_channel::_state, ast_channel::adsicpe, ast_channel::alertpipe, ast_app_group_update(), ast_cause2str(), ast_channel_free(), ast_channel_lock, ast_channel_unlock, ast_channel_whisper_stop(), ast_clear_flag, ast_copy_flags, AST_FLAG_BLOCKING, AST_FLAG_EXCEPTION, AST_FLAG_WHISPER, AST_FLAG_ZOMBIE, AST_GENERATOR_FD, AST_LIST_FIRST, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_HEAD_SET_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log(), AST_MAX_FDS, ast_mutex_lock(), ast_mutex_unlock(), ast_null_frame, ast_queue_frame(), ast_set_flag, ast_set_read_format(), ast_set_write_format(), AST_SOFTHANGUP_DEV, ast_string_field_set, ast_test_flag, AST_TIMING_FD, ast_channel::blocker, ast_channel::cdr, ast_channel_spy::chan, ast_channel::cid, clone_variables(), EVENT_FLAG_CALL, ast_channel::fdno, ast_channel::fds, ast_channel_tech::fixup, free_translation(), ast_channel_tech::hangup, ast_channel::hangupcause, language, ast_channel_spy::lock, ast_channel::lock, LOG_DEBUG, LOG_WARNING, manager_event(), ast_channel::masq, ast_channel::masqr, ast_channel::monitor, musicclass, name, ast_channel::nativeformats, option_debug, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::spies, t, ast_channel::tech, ast_channel::tech_pvt, ast_channel::timingfd, ast_channel_tech::type, ast_channel::whisper, and ast_channel::writeformat.

03530 {
03531    int x,i;
03532    int res=0;
03533    int origstate;
03534    struct ast_frame *cur;
03535    const struct ast_channel_tech *t;
03536    void *t_pvt;
03537    struct ast_callerid tmpcid;
03538    struct ast_channel *clone = original->masq;
03539    struct ast_channel_spy_list *spy_list = NULL;
03540    struct ast_channel_spy *spy = NULL;
03541    struct ast_cdr *cdr;
03542    int rformat = original->readformat;
03543    int wformat = original->writeformat;
03544    char newn[100];
03545    char orig[100];
03546    char masqn[100];
03547    char zombn[100];
03548 
03549    if (option_debug > 3)
03550       ast_log(LOG_DEBUG, "Actually Masquerading %s(%d) into the structure of %s(%d)\n",
03551          clone->name, clone->_state, original->name, original->_state);
03552 
03553    /* XXX This is a seriously wacked out operation.  We're essentially putting the guts of
03554       the clone channel into the original channel.  Start by killing off the original
03555       channel's backend.   I'm not sure we're going to keep this function, because
03556       while the features are nice, the cost is very high in terms of pure nastiness. XXX */
03557 
03558    /* We need the clone's lock, too */
03559    ast_channel_lock(clone);
03560 
03561    if (option_debug > 1)
03562       ast_log(LOG_DEBUG, "Got clone lock for masquerade on '%s' at %p\n", clone->name, &clone->lock);
03563 
03564    /* Having remembered the original read/write formats, we turn off any translation on either
03565       one */
03566    free_translation(clone);
03567    free_translation(original);
03568 
03569 
03570    /* Unlink the masquerade */
03571    original->masq = NULL;
03572    clone->masqr = NULL;
03573    
03574    /* Save the original name */
03575    ast_copy_string(orig, original->name, sizeof(orig));
03576    /* Save the new name */
03577    ast_copy_string(newn, clone->name, sizeof(newn));
03578    /* Create the masq name */
03579    snprintf(masqn, sizeof(masqn), "%s<MASQ>", newn);
03580       
03581    /* Copy the name from the clone channel */
03582    ast_string_field_set(original, name, newn);
03583 
03584    /* Mangle the name of the clone channel */
03585    ast_string_field_set(clone, name, masqn);
03586    
03587    /* Notify any managers of the change, first the masq then the other */
03588    manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", newn, masqn, clone->uniqueid);
03589    manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", orig, newn, original->uniqueid);
03590 
03591    /* Swap the technologies */   
03592    t = original->tech;
03593    original->tech = clone->tech;
03594    clone->tech = t;
03595 
03596    /* Swap the cdrs */
03597    cdr = original->cdr;
03598    original->cdr = clone->cdr;
03599    clone->cdr = cdr;
03600 
03601    t_pvt = original->tech_pvt;
03602    original->tech_pvt = clone->tech_pvt;
03603    clone->tech_pvt = t_pvt;
03604 
03605    /* Swap the readq's */
03606    cur = AST_LIST_FIRST(&original->readq);
03607    AST_LIST_HEAD_SET_NOLOCK(&original->readq, AST_LIST_FIRST(&clone->readq));
03608    AST_LIST_HEAD_SET_NOLOCK(&clone->readq, cur);
03609 
03610    /* Swap the alertpipes */
03611    for (i = 0; i < 2; i++) {
03612       x = original->alertpipe[i];
03613       original->alertpipe[i] = clone->alertpipe[i];
03614       clone->alertpipe[i] = x;
03615    }
03616 
03617    /* Swap the raw formats */
03618    x = original->rawreadformat;
03619    original->rawreadformat = clone->rawreadformat;
03620    clone->rawreadformat = x;
03621    x = original->rawwriteformat;
03622    original->rawwriteformat = clone->rawwriteformat;
03623    clone->rawwriteformat = x;
03624 
03625    /* Swap the spies */
03626    spy_list = original->spies;
03627    original->spies = clone->spies;
03628    clone->spies = spy_list;
03629 
03630    /* Update channel on respective spy lists if present */
03631    if (original->spies) {
03632       AST_LIST_TRAVERSE(&original->spies->list, spy, list) {
03633          ast_mutex_lock(&spy->lock);
03634          spy->chan = original;
03635          ast_mutex_unlock(&spy->lock);
03636       }
03637    }
03638    if (clone->spies) {
03639       AST_LIST_TRAVERSE(&clone->spies->list, spy, list) {
03640          ast_mutex_lock(&spy->lock);
03641          spy->chan = clone;
03642          ast_mutex_unlock(&spy->lock);
03643       }
03644    }
03645 
03646    /* Save any pending frames on both sides.  Start by counting
03647     * how many we're going to need... */
03648    x = 0;
03649    if (original->alertpipe[1] > -1) {
03650       AST_LIST_TRAVERSE(&clone->readq, cur, frame_list)
03651          x++;
03652    }
03653 
03654    /* If we had any, prepend them to the ones already in the queue, and 
03655     * load up the alertpipe */
03656    if (AST_LIST_FIRST(&clone->readq)) {
03657       AST_LIST_INSERT_TAIL(&clone->readq, AST_LIST_FIRST(&original->readq), frame_list);
03658       AST_LIST_HEAD_SET_NOLOCK(&original->readq, AST_LIST_FIRST(&clone->readq));
03659       AST_LIST_HEAD_SET_NOLOCK(&clone->readq, NULL);
03660       for (i = 0; i < x; i++)
03661          write(original->alertpipe[1], &x, sizeof(x));
03662    }
03663    
03664    clone->_softhangup = AST_SOFTHANGUP_DEV;
03665 
03666 
03667    /* And of course, so does our current state.  Note we need not
03668       call ast_setstate since the event manager doesn't really consider
03669       these separate.  We do this early so that the clone has the proper
03670       state of the original channel. */
03671    origstate = original->_state;
03672    original->_state = clone->_state;
03673    clone->_state = origstate;
03674 
03675    if (clone->tech->fixup){
03676       res = clone->tech->fixup(original, clone);
03677       if (res)
03678          ast_log(LOG_WARNING, "Fixup failed on channel %s, strange things may happen.\n", clone->name);
03679    }
03680 
03681    /* Start by disconnecting the original's physical side */
03682    if (clone->tech->hangup)
03683       res = clone->tech->hangup(clone);
03684    if (res) {
03685       ast_log(LOG_WARNING, "Hangup failed!  Strange things may happen!\n");
03686       ast_channel_unlock(clone);
03687       return -1;
03688    }
03689    
03690    snprintf(zombn, sizeof(zombn), "%s<ZOMBIE>", orig);
03691    /* Mangle the name of the clone channel */
03692    ast_string_field_set(clone, name, zombn);
03693    manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", masqn, zombn, clone->uniqueid);
03694 
03695    /* Update the type. */
03696    t_pvt = original->monitor;
03697    original->monitor = clone->monitor;
03698    clone->monitor = t_pvt;
03699    
03700    /* Keep the same language.  */
03701    ast_string_field_set(original, language, clone->language);
03702    /* Copy the FD's other than the generator fd */
03703    for (x = 0; x < AST_MAX_FDS; x++) {
03704       if (x != AST_GENERATOR_FD)
03705          original->fds[x] = clone->fds[x];
03706    }
03707 
03708    ast_app_group_update(clone, original);
03709 
03710    /* move any whisperer over */
03711    ast_channel_whisper_stop(original);
03712    if (ast_test_flag(clone, AST_FLAG_WHISPER)) {
03713       original->whisper = clone->whisper;
03714       ast_set_flag(original, AST_FLAG_WHISPER);
03715       clone->whisper = NULL;
03716       ast_clear_flag(clone, AST_FLAG_WHISPER);
03717    }
03718 
03719    /* Move data stores over */
03720    if (AST_LIST_FIRST(&clone->datastores))
03721                 AST_LIST_INSERT_TAIL(&original->datastores, AST_LIST_FIRST(&clone->datastores), entry);
03722    AST_LIST_HEAD_INIT_NOLOCK(&clone->datastores);
03723 
03724    clone_variables(original, clone);
03725    /* Presense of ADSI capable CPE follows clone */
03726    original->adsicpe = clone->adsicpe;
03727    /* Bridge remains the same */
03728    /* CDR fields remain the same */
03729    /* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */
03730    /* Application and data remain the same */
03731    /* Clone exception  becomes real one, as with fdno */
03732    ast_copy_flags(original, clone, AST_FLAG_EXCEPTION);
03733    original->fdno = clone->fdno;
03734    /* Schedule context remains the same */
03735    /* Stream stuff stays the same */
03736    /* Keep the original state.  The fixup code will need to work with it most likely */
03737 
03738    /* Just swap the whole structures, nevermind the allocations, they'll work themselves
03739       out. */
03740    tmpcid = original->cid;
03741    original->cid = clone->cid;
03742    clone->cid = tmpcid;
03743    
03744    /* Restore original timing file descriptor */
03745    original->fds[AST_TIMING_FD] = original->timingfd;
03746    
03747    /* Our native formats are different now */
03748    original->nativeformats = clone->nativeformats;
03749    
03750    /* Context, extension, priority, app data, jump table,  remain the same */
03751    /* pvt switches.  pbx stays the same, as does next */
03752    
03753    /* Set the write format */
03754    ast_set_write_format(original, wformat);
03755 
03756    /* Set the read format */
03757    ast_set_read_format(original, rformat);
03758 
03759    /* Copy the music class */
03760    ast_string_field_set(original, musicclass, clone->musicclass);
03761 
03762    if (option_debug)
03763       ast_log(LOG_DEBUG, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat);
03764 
03765    /* Okay.  Last thing is to let the channel driver know about all this mess, so he
03766       can fix up everything as best as possible */
03767    if (original->tech->fixup) {
03768       res = original->tech->fixup(clone, original);
03769       if (res) {
03770          ast_log(LOG_WARNING, "Channel for type '%s' could not fixup channel %s\n",
03771             original->tech->type, original->name);
03772          ast_channel_unlock(clone);
03773          return -1;
03774       }
03775    } else
03776       ast_log(LOG_WARNING, "Channel type '%s' does not have a fixup routine (for %s)!  Bad things may happen.\n",
03777          original->tech->type, original->name);
03778    
03779    /* Now, at this point, the "clone" channel is totally F'd up.  We mark it as
03780       a zombie so nothing tries to touch it.  If it's already been marked as a
03781       zombie, then free it now (since it already is considered invalid). */
03782    if (ast_test_flag(clone, AST_FLAG_ZOMBIE)) {
03783       if (option_debug)
03784          ast_log(LOG_DEBUG, "Destroying channel clone '%s'\n", clone->name);
03785       ast_channel_unlock(clone);
03786       manager_event(EVENT_FLAG_CALL, "Hangup",
03787          "Channel: %s\r\n"
03788          "Uniqueid: %s\r\n"
03789          "Cause: %d\r\n"
03790          "Cause-txt: %s\r\n",
03791          clone->name,
03792          clone->uniqueid,
03793          clone->hangupcause,
03794          ast_cause2str(clone->hangupcause)
03795          );
03796       ast_channel_free(clone);
03797    } else {
03798       if (option_debug)
03799          ast_log(LOG_DEBUG, "Released clone lock on '%s'\n", clone->name);
03800       ast_set_flag(clone, AST_FLAG_ZOMBIE);
03801       ast_queue_frame(clone, &ast_null_frame);
03802       ast_channel_unlock(clone);
03803    }
03804    
03805    /* Signal any blocker */
03806    if (ast_test_flag(original, AST_FLAG_BLOCKING))
03807       pthread_kill(original->blocker, SIGURG);
03808    if (option_debug)
03809       ast_log(LOG_DEBUG, "Done Masquerading %s (%d)\n", original->name, original->_state);
03810    return 0;
03811 }

static int ast_fdisset ( struct pollfd pfds,
int  fd,
int  max,
int *  start 
) [inline, static]

Helper function for migrating select to poll.

Definition at line 1238 of file channel.h.

References pollfd::revents.

Referenced by do_monitor().

01239 {
01240    int x;
01241    int dummy=0;
01242 
01243    if (fd < 0)
01244       return 0;
01245    if (!start)
01246       start = &dummy;
01247    for (x = *start; x<max; x++)
01248       if (pfds[x].fd == fd) {
01249          if (x == *start)
01250             (*start)++;
01251          return pfds[x].revents;
01252       }
01253    return 0;
01254 }

struct ast_channel* ast_get_channel_by_exten_locked ( const char *  exten,
const char *  context 
) [read]

Get channel by exten (and optionally context) and lock it.

Definition at line 1136 of file channel.c.

References channel_find_locked().

01137 {
01138    return channel_find_locked(NULL, NULL, 0, context, exten);
01139 }

struct ast_channel* ast_get_channel_by_name_locked ( const char *  name  )  [read]

Get channel by name (locks channel).

Definition at line 1117 of file channel.c.

References channel_find_locked().

01118 {
01119    return channel_find_locked(NULL, name, 0, NULL, NULL);
01120 }

struct ast_channel* ast_get_channel_by_name_prefix_locked ( const char *  name,
const int  namelen 
) [read]

Get channel by name prefix (locks channel).

Definition at line 1123 of file channel.c.

References channel_find_locked().

01124 {
01125    return channel_find_locked(NULL, name, namelen, NULL, NULL);
01126 }

struct ast_channel_tech* ast_get_channel_tech ( const char *  name  )  [read]

Get a channel technology structure by name.

Parameters:
name name of technology to find
Returns:
a pointer to the structure, or NULL if no matching technology found

Definition at line 571 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.

00572 {
00573    struct chanlist *chanls;
00574    const struct ast_channel_tech *ret = NULL;
00575 
00576    if (AST_LIST_LOCK(&channels)) {
00577       ast_log(LOG_WARNING, "Unable to lock channel tech list\n");
00578       return NULL;
00579    }
00580 
00581    AST_LIST_TRAVERSE(&backends, chanls, list) {
00582       if (!strcasecmp(name, chanls->tech->type)) {
00583          ret = chanls->tech;
00584          break;
00585       }
00586    }
00587 
00588    AST_LIST_UNLOCK(&channels);
00589    
00590    return ret;
00591 }

ast_group_t ast_get_group ( const char *  s  ) 

Definition at line 4494 of file channel.c.

References ast_log(), ast_strdupa, group, LOG_ERROR, LOG_WARNING, and strsep().

04495 {
04496    char *piece;
04497    char *c;
04498    int start=0, finish=0, x;
04499    ast_group_t group = 0;
04500 
04501    c = ast_strdupa(s);
04502    
04503    while ((piece = strsep(&c, ","))) {
04504       if (sscanf(piece, "%d-%d", &start, &finish) == 2) {
04505          /* Range */
04506       } else if (sscanf(piece, "%d", &start)) {
04507          /* Just one */
04508          finish = start;
04509       } else {
04510          ast_log(LOG_ERROR, "Syntax error parsing group configuration '%s' at '%s'. Ignoring.\n", s, piece);
04511          continue;
04512       }
04513       for (x = start; x <= finish; x++) {
04514          if ((x > 63) || (x < 0)) {
04515             ast_log(LOG_WARNING, "Ignoring invalid group %d (maximum group is 63)\n", x);
04516          } else
04517             group |= ((ast_group_t) 1 << x);
04518       }
04519    }
04520    return group;
04521 }

int ast_hangup ( struct ast_channel chan  ) 

Hang up a channel.

Note:
This function performs a hard hangup on a channel. Unlike the soft-hangup, this function performs all stream stopping, etc, on the channel that needs to end. chan is no longer valid after this call.
Parameters:
chan channel to hang up
Returns:
Returns 0 on success, -1 on failure.

Definition at line 1703 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.

01704 {
01705    int res = 0;
01706    struct ast_cdr *cdr = NULL;
01707 
01708    /* Don't actually hang up a channel that will masquerade as someone else, or
01709       if someone is going to masquerade as us */
01710    ast_channel_lock(chan);
01711 
01712    detach_spies(chan);     /* get rid of spies */
01713 
01714    if (chan->masq) {
01715       if (ast_do_masquerade(chan))
01716          ast_log(LOG_WARNING, "Failed to perform masquerade\n");
01717    }
01718 
01719    if (chan->masq) {
01720       ast_log(LOG_WARNING, "%s getting hung up, but someone is trying to masq into us?!?\n", chan->name);
01721       ast_channel_unlock(chan);
01722       return 0;
01723    }
01724    /* If this channel is one which will be masqueraded into something,
01725       mark it as a zombie already, so we know to free it later */
01726    if (chan->masqr) {
01727       ast_set_flag(chan, AST_FLAG_ZOMBIE);
01728       ast_channel_unlock(chan);
01729       return 0;
01730    }
01731    free_translation(chan);
01732    /* Close audio stream */
01733    if (chan->stream) {
01734       ast_closestream(chan->stream);
01735       chan->stream = NULL;
01736    }
01737    /* Close video stream */
01738    if (chan->vstream) {
01739       ast_closestream(chan->vstream);
01740       chan->vstream = NULL;
01741    }
01742    if (chan->sched) {
01743       sched_context_destroy(chan->sched);
01744       chan->sched = NULL;
01745    }
01746    
01747    if (chan->generatordata)   /* Clear any tone stuff remaining */
01748       chan->generator->release(chan, chan->generatordata);
01749    chan->generatordata = NULL;
01750    chan->generator = NULL;
01751    if (chan->cdr) {     /* End the CDR if it hasn't already */
01752       ast_cdr_end(chan->cdr);
01753       cdr = chan->cdr;
01754       chan->cdr = NULL;
01755    }
01756    if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
01757       ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd "
01758                "is blocked by thread %ld in procedure %s!  Expect a failure\n",
01759                (long)pthread_self(), chan->name, (long)chan->blocker, chan->blockproc);
01760       CRASH;
01761    }
01762    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE)) {
01763       if (option_debug)
01764          ast_log(LOG_DEBUG, "Hanging up channel '%s'\n", chan->name);
01765       if (chan->tech->hangup)
01766          res = chan->tech->hangup(chan);
01767    } else {
01768       if (option_debug)
01769          ast_log(LOG_DEBUG, "Hanging up zombie '%s'\n", chan->name);
01770    }
01771          
01772    ast_channel_unlock(chan);
01773    manager_event(EVENT_FLAG_CALL, "Hangup",
01774          "Channel: %s\r\n"
01775          "Uniqueid: %s\r\n"
01776          "Cause: %d\r\n"
01777          "Cause-txt: %s\r\n",
01778          chan->name,
01779          chan->uniqueid,
01780          chan->hangupcause,
01781          ast_cause2str(chan->hangupcause)
01782          );
01783    ast_channel_free(chan);
01784 
01785    if (cdr)
01786       ast_cdr_detach(cdr);
01787 
01788    return res;
01789 }

int ast_indicate ( struct ast_channel chan,
int  condition 
)

Indicates condition of channel.

Note:
Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
Parameters:
chan channel to change the indication
condition which condition to indicate on the channel
Returns:
Returns 0 on success, -1 on failure

Definition at line 2557 of file channel.c.

References ast_indicate_data().

02558 {
02559    return ast_indicate_data(chan, condition, NULL, 0);
02560 }

int ast_indicate_data ( struct ast_channel chan,
int  condition,
const void *  data,
size_t  datalen 
)

Indicates condition of channel, with payload.

Note:
Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
Parameters:
chan channel to change the indication
condition which condition to indicate on the channel
data pointer to payload data
datalen size of payload data
Returns:
Returns 0 on success, -1 on failure

Definition at line 2562 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.

02563 {
02564    int res = -1;
02565 
02566    ast_channel_lock(chan);
02567    /* Stop if we're a zombie or need a soft hangup */
02568    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
02569       ast_channel_unlock(chan);
02570       return -1;
02571    }
02572    if (chan->tech->indicate)
02573       res = chan->tech->indicate(chan, condition, data, datalen);
02574    ast_channel_unlock(chan);
02575    if (!chan->tech->indicate || res) {
02576       /*
02577        * Device does not support (that) indication, lets fake
02578        * it by doing our own tone generation. (PM2002)
02579        */
02580       if (condition < 0)
02581          ast_playtones_stop(chan);
02582       else {
02583          const struct tone_zone_sound *ts = NULL;
02584          switch (condition) {
02585          case AST_CONTROL_RINGING:
02586             ts = ast_get_indication_tone(chan->zone, "ring");
02587             break;
02588          case AST_CONTROL_BUSY:
02589             ts = ast_get_indication_tone(chan->zone, "busy");
02590             break;
02591          case AST_CONTROL_CONGESTION:
02592             ts = ast_get_indication_tone(chan->zone, "congestion");
02593             break;
02594          }
02595          if (ts && ts->data[0]) {
02596             if (option_debug)
02597                ast_log(LOG_DEBUG, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition);
02598             ast_playtones_start(chan,0,ts->data, 1);
02599             res = 0;
02600          } else if (condition == AST_CONTROL_PROGRESS) {
02601             /* ast_playtones_stop(chan); */
02602          } else if (condition == AST_CONTROL_PROCEEDING) {
02603             /* Do nothing, really */
02604          } else if (condition == AST_CONTROL_HOLD) {
02605             /* Do nothing.... */
02606          } else if (condition == AST_CONTROL_UNHOLD) {
02607             /* Do nothing.... */
02608          } else if (condition == AST_CONTROL_VIDUPDATE) {
02609             /* Do nothing.... */
02610          } else {
02611             /* not handled */
02612             ast_log(LOG_WARNING, "Unable to handle indication %d for '%s'\n", condition, chan->name);
02613             res = -1;
02614          }
02615       }
02616    }
02617    return res;
02618 }

int ast_internal_timing_enabled ( struct ast_channel chan  ) 

Check if the channel can run in internal timing mode.

Parameters:
chan The channel to check
Returns:
boolean
This function will return 1 if internal timing is enabled and the timing device is available.

Definition at line 2539 of file channel.c.

References ast_log(), ast_opt_internal_timing, LOG_DEBUG, option_debug, and ast_channel::timingfd.

02540 {
02541    int ret = ast_opt_internal_timing && chan->timingfd > -1;
02542    if (option_debug > 4)
02543       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);
02544    return ret;
02545 }

char* ast_print_group ( char *  buf,
int  buflen,
ast_group_t  group 
)

print call- and pickup groups into buffer

Definition at line 4576 of file channel.c.

04577 {
04578    unsigned int i;
04579    int first=1;
04580    char num[3];
04581 
04582    buf[0] = '\0';
04583    
04584    if (!group) /* Return empty string if no group */
04585       return buf;
04586 
04587    for (i = 0; i <= 63; i++) {   /* Max group is 63 */
04588       if (group & ((ast_group_t) 1 << i)) {
04589             if (!first) {
04590             strncat(buf, ", ", buflen);
04591          } else {
04592             first=0;
04593          }
04594          snprintf(num, sizeof(num), "%u", i);
04595          strncat(buf, num, buflen);
04596       }
04597    }
04598    return buf;
04599 }

int ast_prod ( struct ast_channel chan  ) 

Send empty audio to prime a channel driver.

Definition at line 2740 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.

02741 {
02742    struct ast_frame a = { AST_FRAME_VOICE };
02743    char nothing[128];
02744 
02745    /* Send an empty audio frame to get things moving */
02746    if (chan->_state != AST_STATE_UP) {
02747       if (option_debug)
02748          ast_log(LOG_DEBUG, "Prodding channel '%s'\n", chan->name);
02749       a.subclass = chan->rawwriteformat;
02750       a.data = nothing + AST_FRIENDLY_OFFSET;
02751       a.src = "ast_prod";
02752       if (ast_write(chan, &a))
02753          ast_log(LOG_WARNING, "Prodding channel '%s' failed\n", chan->name);
02754    }
02755    return 0;
02756 }

int ast_queue_control ( struct ast_channel chan,
enum ast_control_frame_type  control 
)

Queue a control frame with payload.

Parameters:
chan channel to queue frame onto
control type of control frame
Returns:
zero on success, non-zero on failure

Definition at line 963 of file channel.c.

References AST_FRAME_CONTROL, ast_queue_frame(), and ast_frame::subclass.

00964 {
00965    struct ast_frame f = { AST_FRAME_CONTROL, };
00966 
00967    f.subclass = control;
00968 
00969    return ast_queue_frame(chan, &f);
00970 }

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.

Parameters:
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
Returns:
zero on success, non-zero on failure
The supplied payload data is copied into the frame, so the caller's copy is not modified nor freed, and the resulting frame will retain a copy of the data even if the caller frees their local copy.

Note:
This method should be treated as a 'network transport'; in other words, your frames may be transferred across an IAX2 channel to another system, which may be a different endianness than yours. Because of this, you should ensure that either your frames will never be expected to work across systems, or that you always put your payload data into 'network byte order' before calling this function.

Definition at line 973 of file channel.c.

References AST_FRAME_CONTROL, ast_queue_frame(), ast_frame::data, ast_frame::datalen, and ast_frame::subclass.

00975 {
00976    struct ast_frame f = { AST_FRAME_CONTROL, };
00977 
00978    f.subclass = control;
00979    f.data = (void *) data;
00980    f.datalen = datalen;
00981 
00982    return ast_queue_frame(chan, &f);
00983 }

int ast_queue_frame ( struct ast_channel chan,
struct ast_frame fin 
)

Queue an outgoing frame.

Definition at line 895 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.

00896 {
00897    struct ast_frame *f;
00898    struct ast_frame *cur;
00899    int blah = 1;
00900    int qlen = 0;
00901 
00902    /* Build us a copy and free the original one */
00903    if (!(f = ast_frdup(fin))) {
00904       ast_log(LOG_WARNING, "Unable to duplicate frame\n");
00905       return -1;
00906    }
00907    ast_channel_lock(chan);
00908 
00909    /* See if the last frame on the queue is a hangup, if so don't queue anything */
00910    if ((cur = AST_LIST_LAST(&chan->readq)) && (cur->frametype == AST_FRAME_CONTROL) && (cur->subclass == AST_CONTROL_HANGUP)) {
00911       ast_frfree(f);
00912       ast_channel_unlock(chan);
00913       return 0;
00914    }
00915 
00916    /* Count how many frames exist on the queue */
00917    AST_LIST_TRAVERSE(&chan->readq, cur, frame_list) {
00918       qlen++;
00919    }
00920 
00921    /* Allow up to 96 voice frames outstanding, and up to 128 total frames */
00922    if (((fin->frametype == AST_FRAME_VOICE) && (qlen > 96)) || (qlen  > 128)) {
00923       if (fin->frametype != AST_FRAME_VOICE) {
00924          ast_log(LOG_WARNING, "Exceptionally long queue length queuing to %s\n", chan->name);
00925          CRASH;
00926       } else {
00927          if (option_debug)
00928             ast_log(LOG_DEBUG, "Dropping voice to exceptionally long queue on %s\n", chan->name);
00929          ast_frfree(f);
00930          ast_channel_unlock(chan);
00931          return 0;
00932       }
00933    }
00934    AST_LIST_INSERT_TAIL(&chan->readq, f, frame_list);
00935    if (chan->alertpipe[1] > -1) {
00936       if (write(chan->alertpipe[1], &blah, sizeof(blah)) != sizeof(blah))
00937          ast_log(LOG_WARNING, "Unable to write to alert pipe on %s, frametype/subclass %d/%d (qlen = %d): %s!\n",
00938             chan->name, f->frametype, f->subclass, qlen, strerror(errno));
00939 #ifdef HAVE_ZAPTEL
00940    } else if (chan->timingfd > -1) {
00941       ioctl(chan->timingfd, ZT_TIMERPING, &blah);
00942 #endif            
00943    } else if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
00944       pthread_kill(chan->blocker, SIGURG);
00945    }
00946    ast_channel_unlock(chan);
00947    return 0;
00948 }

int ast_queue_hangup ( struct ast_channel chan  ) 

Queue a hangup frame.

Definition at line 951 of file channel.c.

References ast_channel::_softhangup, ast_channel_trylock, ast_channel_unlock, AST_CONTROL_HANGUP, AST_FRAME_CONTROL, ast_queue_frame(), and AST_SOFTHANGUP_DEV.

00952 {
00953    struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP };
00954    /* Yeah, let's not change a lock-critical value without locking */
00955    if (!ast_channel_trylock(chan)) {
00956       chan->_softhangup |= AST_SOFTHANGUP_DEV;
00957       ast_channel_unlock(chan);
00958    }
00959    return ast_queue_frame(chan, &f);
00960 }

struct ast_frame* ast_read ( struct ast_channel chan  )  [read]

Reads a frame.

Parameters:
chan channel to read a frame from Read a frame.
Returns:
Returns a frame, or NULL on error. If it returns NULL, you best just stop reading frames and assume the channel has been disconnected.

Definition at line 2547 of file channel.c.

References __ast_read().

02548 {
02549    return __ast_read(chan, 0);
02550 }

struct ast_frame* ast_read_noaudio ( struct ast_channel chan  )  [read]

Reads a frame, returning AST_FRAME_NULL frame if audio. Read a frame.

Parameters:
chan channel to read a frame from
Returns:
Returns a frame, or NULL on error. If it returns NULL, you best just stop reading frames and assume the channel has been disconnected.
Note:
Audio is replaced with AST_FRAME_NULL to avoid transcode when the resulting audio is not necessary.

Definition at line 2552 of file channel.c.

References __ast_read().

02553 {
02554    return __ast_read(chan, 1);
02555 }

int ast_readstring ( struct ast_channel c,
char *  s,
int  len,
int  timeout,
int  rtimeout,
char *  enders 
)

Reads multiple digits

Parameters:
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 3258 of file channel.c.

References ast_readstring_full().

03259 {
03260    return ast_readstring_full(c, s, len, timeout, ftimeout, enders, -1, -1);
03261 }

int ast_readstring_full ( struct ast_channel c,
char *  s,
int  len,
int  timeout,
int  rtimeout,
char *  enders,
int  audiofd,
int  ctrlfd 
)

Definition at line 3263 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.

03264 {
03265    int pos = 0;   /* index in the buffer where we accumulate digits */
03266    int to = ftimeout;
03267 
03268    /* Stop if we're a zombie or need a soft hangup */
03269    if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
03270       return -1;
03271    if (!len)
03272       return -1;
03273    for (;;) {
03274       int d;
03275       if (c->stream) {
03276          d = ast_waitstream_full(c, AST_DIGIT_ANY, audiofd, ctrlfd);
03277          ast_stopstream(c);
03278          usleep(1000);
03279          if (!d)
03280             d = ast_waitfordigit_full(c, to, audiofd, ctrlfd);
03281       } else {
03282          d = ast_waitfordigit_full(c, to, audiofd, ctrlfd);
03283       }
03284       if (d < 0)
03285          return -1;
03286       if (d == 0) {
03287          s[pos]='\0';
03288          return 1;
03289       }
03290       if (d == 1) {
03291          s[pos]='\0';
03292          return 2;
03293       }
03294       if (!strchr(enders, d))
03295          s[pos++] = d;
03296       if (strchr(enders, d) || (pos >= len)) {
03297          s[pos]='\0';
03298          return 0;
03299       }
03300       to = timeout;
03301    }
03302    /* Never reached */
03303    return 0;
03304 }

int ast_recvchar ( struct ast_channel chan,
int  timeout 
)

Receives a text character from a channel.

Parameters:
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 2620 of file channel.c.

References ast_recvtext(), and free.

02621 {
02622    int c;
02623    char *buf = ast_recvtext(chan, timeout);
02624    if (buf == NULL)
02625       return -1;  /* error or timeout */
02626    c = *(unsigned char *)buf;
02627    free(buf);
02628    return c;
02629 }

char* ast_recvtext ( struct ast_channel chan,
int  timeout 
)

Receives a text string from a channel Read a string of text from a channel.

Parameters:
chan channel to act upon
timeout timeout in milliseconds (0 for infinite wait)
Returns:
the received text, or NULL to signify failure.

Definition at line 2631 of file channel.c.

References ast_check_hangup(), AST_CONTROL_HANGUP, AST_FRAME_CONTROL, AST_FRAME_TEXT, ast_frfree(), ast_read(), ast_strndup, ast_waitfor(), ast_frame::data, ast_frame::datalen, f, ast_frame::frametype, and ast_frame::subclass.

02632 {
02633    int res, done = 0;
02634    char *buf = NULL;
02635    
02636    while (!done) {
02637       struct ast_frame *f;
02638       if (ast_check_hangup(chan))
02639          break;
02640       res = ast_waitfor(chan, timeout);
02641       if (res <= 0) /* timeout or error */
02642          break;
02643       timeout = res; /* update timeout */
02644       f = ast_read(chan);
02645       if (f == NULL)
02646          break; /* no frame */
02647       if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP)
02648          done = 1;   /* force a break */
02649       else if (f->frametype == AST_FRAME_TEXT) {      /* what we want */
02650          buf = ast_strndup((char *) f->data, f->datalen);   /* dup and break */
02651          done = 1;
02652       }
02653       ast_frfree(f);
02654    }
02655    return buf;
02656 }

struct ast_channel* ast_request ( const char *  type,
int  format,
void *  data,
int *  status 
) [read]

Requests a channel.

Parameters:
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
Returns:
Returns an ast_channel on success, NULL on failure.

Definition at line 3166 of file channel.c.

References AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, 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(), ast_channel_tech::capabilities, capabilities, fmt, LOG_WARNING, ast_channel_tech::requester, chanlist::tech, and ast_channel_tech::type.

03167 {
03168    struct chanlist *chan;
03169    struct ast_channel *c;
03170    int capabilities;
03171    int fmt;
03172    int res;
03173    int foo;
03174    int videoformat = format & AST_FORMAT_VIDEO_MASK;
03175 
03176    if (!cause)
03177       cause = &foo;
03178    *cause = AST_CAUSE_NOTDEFINED;
03179 
03180    if (AST_LIST_LOCK(&channels)) {
03181       ast_log(LOG_WARNING, "Unable to lock channel list\n");
03182       return NULL;
03183    }
03184 
03185    AST_LIST_TRAVERSE(&backends, chan, list) {
03186       if (strcasecmp(type, chan->tech->type))
03187          continue;
03188 
03189       capabilities = chan->tech->capabilities;
03190       fmt = format & AST_FORMAT_AUDIO_MASK;
03191       res = ast_translator_best_choice(&fmt, &capabilities);
03192       if (res < 0) {
03193          ast_log(LOG_WARNING, "No translator path exists for channel type %s (native %d) to %d\n", type, chan->tech->capabilities, format);
03194          *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
03195          AST_LIST_UNLOCK(&channels);
03196          return NULL;
03197       }
03198       AST_LIST_UNLOCK(&channels);
03199       if (!chan->tech->requester)
03200          return NULL;
03201       
03202       if (!(c = chan->tech->requester(type, capabilities | videoformat, data, cause)))
03203          return NULL;
03204 
03205       /* no need to generate a Newchannel event here; it is done in the channel_alloc call */
03206       return c;
03207    }
03208 
03209    ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
03210    *cause = AST_CAUSE_NOSUCHDRIVER;
03211    AST_LIST_UNLOCK(&channels);
03212 
03213    return NULL;
03214 }

struct ast_channel* ast_request_and_dial ( const char *  type,
int  format,
void *  data,
int  timeout,
int *  reason,
const char *  cidnum,
const char *  cidname 
) [read]

Request a channel of a given type, with data as optional information used by the low level module and attempt to place a call on it.

Parameters:
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
Returns:
Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state to know if the call was answered or not.

Definition at line 3161 of file channel.c.

References __ast_request_and_dial().

03162 {
03163    return __ast_request_and_dial(type, format, data, timeout, outstate, cidnum, cidname, NULL);
03164 }

int ast_safe_sleep ( struct ast_channel chan,
int  ms 
)

Wait for a specied amount of time, looking for hangups.

Parameters:
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.
Returns:
returns -1 on hangup, otherwise 0.

Definition at line 1170 of file channel.c.

References ast_safe_sleep_conditional().

01171 {
01172    return ast_safe_sleep_conditional(chan, ms, NULL, NULL);
01173 }

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.

Parameters:
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
Returns:
returns -1 on hangup, otherwise 0. Waits for a specified amount of time, servicing the channel as required. If cond returns 0, this function returns.

Definition at line 1149 of file channel.c.

References ast_frfree(), ast_read(), ast_waitfor(), cond, and f.

01150 {
01151    struct ast_frame *f;
01152 
01153    while (ms > 0) {
01154       if (cond && ((*cond)(data) == 0))
01155          return 0;
01156       ms = ast_waitfor(chan, ms);
01157       if (ms < 0)
01158          return -1;
01159       if (ms > 0) {
01160          f = ast_read(chan);
01161          if (!f)
01162             return -1;
01163          ast_frfree(f);
01164       }
01165    }
01166    return 0;
01167 }

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 428 of file channel.c.

References ast_malloc, and len.

00429 {
00430    char *b2, buf[1];
00431    int len;
00432    va_list args;
00433 
00434    va_start(args, fmt);
00435    len = vsnprintf(buf, 1, fmt, args);
00436    va_end(args);
00437 
00438    if (!(b2 = ast_malloc(len + 1)))
00439       return NULL;
00440 
00441    va_start(args, fmt);
00442    vsnprintf(b2, len + 1,  fmt, args);
00443    va_end(args);
00444 
00445    return b2;
00446 }

static int ast_select ( int  nfds,
fd_set *  rfds,
fd_set *  wfds,
fd_set *  efds,
struct timeval *  tvp 
) [inline, static]

Waits for activity on a group of channels.

Parameters:
nfds the maximum number of file descriptors in the sets
rfds file descriptors to check for read availability
wfds file descriptors to check for write availability
efds file descriptors to check for exceptions (OOB data)
tvp timeout while waiting for events This is the same as a standard select(), except it guarantees the behaviour where the passed struct timeval is updated with how much time was not slept while waiting for the specified events

Definition at line 1279 of file channel.h.

Referenced by do_monitor(), do_parking_thread(), and sound_thread().

01280 {
01281 #ifdef __linux__
01282    return select(nfds, rfds, wfds, efds, tvp);
01283 #else
01284    if (tvp) {
01285       struct timeval tv, tvstart, tvend, tvlen;
01286       int res;
01287 
01288       tv = *tvp;
01289       gettimeofday(&tvstart, NULL);
01290       res = select(nfds, rfds, wfds, efds, tvp);
01291       gettimeofday(&tvend, NULL);
01292       timersub(&tvend, &tvstart, &tvlen);
01293       timersub(&tv, &tvlen, tvp);
01294       if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) {
01295          tvp->tv_sec = 0;
01296          tvp->tv_usec = 0;
01297       }
01298       return res;
01299    }
01300    else
01301       return select(nfds, rfds, wfds, efds, NULL);
01302 #endif
01303 }

int ast_senddigit ( struct ast_channel chan,
char  digit 
)

Send a DTMF digit to a channel Send a DTMF digit to a channel.

Parameters:
chan channel to act upon
digit the DTMF digit to send, encoded in ASCII
Returns:
Returns 0 on success, -1 on failure

Definition at line 2730 of file channel.c.

References AST_DEFAULT_EMULATE_DTMF_DURATION, ast_safe_sleep(), ast_senddigit_begin(), ast_senddigit_end(), ast_channel_tech::send_digit_begin, and ast_channel::tech.

02731 {
02732    if (chan->tech->send_digit_begin) {
02733       ast_senddigit_begin(chan, digit);
02734       ast_safe_sleep(chan, AST_DEFAULT_EMULATE_DTMF_DURATION);
02735    }
02736    
02737    return ast_senddigit_end(chan, digit, AST_DEFAULT_EMULATE_DTMF_DURATION);
02738 }

int ast_senddigit_begin ( struct ast_channel chan,
char  digit 
)

Definition at line 2671 of file channel.c.

References ast_log(), ast_playtones_start(), LOG_DEBUG, option_debug, ast_channel_tech::send_digit_begin, and ast_channel::tech.

02672 {
02673    /* Device does not support DTMF tones, lets fake
02674     * it by doing our own generation. */
02675    static const char* dtmf_tones[] = {
02676       "941+1336", /* 0 */
02677       "697+1209", /* 1 */
02678       "697+1336", /* 2 */
02679       "697+1477", /* 3 */
02680       "770+1209", /* 4 */
02681       "770+1336", /* 5 */
02682       "770+1477", /* 6 */
02683       "852+1209", /* 7 */
02684       "852+1336", /* 8 */
02685       "852+1477", /* 9 */
02686       "697+1633", /* A */
02687       "770+1633", /* B */
02688       "852+1633", /* C */
02689       "941+1633", /* D */
02690       "941+1209", /* * */
02691       "941+1477"  /* # */
02692    };
02693 
02694    if (!chan->tech->send_digit_begin)
02695       return 0;
02696 
02697    if (!chan->tech->send_digit_begin(chan, digit))
02698       return 0;
02699 
02700    if (digit >= '0' && digit <='9')
02701       ast_playtones_start(chan, 0, dtmf_tones[digit-'0'], 0);
02702    else if (digit >= 'A' && digit <= 'D')
02703       ast_playtones_start(chan, 0, dtmf_tones[digit-'A'+10], 0);
02704    else if (digit == '*')
02705       ast_playtones_start(chan, 0, dtmf_tones[14], 0);
02706    else if (digit == '#')
02707       ast_playtones_start(chan, 0, dtmf_tones[15], 0);
02708    else {
02709       /* not handled */
02710       if (option_debug)
02711          ast_log(LOG_DEBUG, "Unable to generate DTMF tone '%c' for '%s'\n", digit, chan->name);
02712    }
02713 
02714    return 0;
02715 }

int ast_senddigit_end ( struct ast_channel chan,
char  digit,
unsigned int  duration 
)

Definition at line 2717 of file channel.c.

References ast_playtones_stop(), ast_channel::generator, ast_channel_tech::send_digit_end, and ast_channel::tech.

02718 {
02719    int res = -1;
02720 
02721    if (chan->tech->send_digit_end)
02722       res = chan->tech->send_digit_end(chan, digit, duration);
02723 
02724    if (res && chan->generator)
02725       ast_playtones_stop(chan);
02726    
02727    return 0;
02728 }

int ast_sendtext ( struct ast_channel chan,
const char *  text 
)

Sends text to a channel Write text to a display on a channel.

Parameters:
chan channel to act upon
text string of text to send on the channel
Returns:
Returns 0 on success, -1 on failure

Definition at line 2658 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.

02659 {
02660    int res = 0;
02661    /* Stop if we're a zombie or need a soft hangup */
02662    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
02663       return -1;
02664    CHECK_BLOCKING(chan);
02665    if (chan->tech->send_text)
02666       res = chan->tech->send_text(chan, text);
02667    ast_clear_flag(chan, AST_FLAG_BLOCKING);
02668    return res;
02669 }

void ast_set_callerid ( struct ast_channel chan,
const char *  cidnum,
const char *  cidname,
const char *  ani 
)

Definition at line 3813 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.

03814 {
03815    if (callerid) {
03816       if (chan->cid.cid_num)
03817          free(chan->cid.cid_num);
03818       chan->cid.cid_num = ast_strdup(callerid);
03819    }
03820    if (calleridname) {
03821       if (chan->cid.cid_name)
03822          free(chan->cid.cid_name);
03823       chan->cid.cid_name = ast_strdup(calleridname);
03824    }
03825    if (ani) {
03826       if (chan->cid.cid_ani)
03827          free(chan->cid.cid_ani);
03828       chan->cid.cid_ani = ast_strdup(ani);
03829    }
03830    if (chan->cdr)
03831       ast_cdr_setcid(chan->cdr, chan);
03832    manager_event(EVENT_FLAG_CALL, "Newcallerid",
03833             "Channel: %s\r\n"
03834             "CallerID: %s\r\n"
03835             "CallerIDName: %s\r\n"
03836             "Uniqueid: %s\r\n"
03837             "CID-CallingPres: %d (%s)\r\n",
03838             chan->name,
03839             S_OR(chan->cid.cid_num, "<Unknown>"),
03840             S_OR(chan->cid.cid_name, "<Unknown>"),
03841             chan->uniqueid,
03842             chan->cid.cid_pres,
03843             ast_describe_caller_presentation(chan->cid.cid_pres)
03844             );
03845 }

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.

Parameters:
chan channel to change
format format to change to
Returns:
Returns 0 on success, -1 on failure

Definition at line 3025 of file channel.c.

References ast_channel::rawreadformat, ast_channel::readformat, ast_channel::readtrans, and set_format().

03026 {
03027    return set_format(chan, fmt, &chan->rawreadformat, &chan->readformat,
03028            &chan->readtrans, 0);
03029 }

void ast_set_variables ( struct ast_channel chan,
struct ast_variable vars 
)

adds a list of channel variables to a channel

Parameters:
chan the channel
vars a linked list of variables
Variable names can be for a regular channel variable or a dialplan function that has the ability to be written to.

Definition at line 4601 of file channel.c.

References ast_variable::name, ast_variable::next, pbx_builtin_setvar_helper(), and ast_variable::value.

04602 {
04603    struct ast_variable *cur;
04604 
04605    for (cur = vars; cur; cur = cur->next)
04606       pbx_builtin_setvar_helper(chan, cur->name, cur->value);  
04607 }

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.

Parameters:
chan channel to change
format new format for writing
Returns:
Returns 0 on success, -1 on failure

Definition at line 3031 of file channel.c.

References ast_channel::rawwriteformat, set_format(), ast_channel::writeformat, and ast_channel::writetrans.

03032 {
03033    return set_format(chan, fmt, &chan->rawwriteformat, &chan->writeformat,
03034            &chan->writetrans, 1);
03035 }

int ast_setstate ( struct ast_channel chan,
enum  ast_channel_state 
)

Change the state of a channel.

Definition at line 3847 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.

03848 {
03849    int oldstate = chan->_state;
03850 
03851    if (oldstate == state)
03852       return 0;
03853 
03854    chan->_state = state;
03855    ast_device_state_changed_literal(chan->name);
03856    /* setstate used to conditionally report Newchannel; this is no more */
03857    manager_event(EVENT_FLAG_CALL,
03858             "Newstate",
03859             "Channel: %s\r\n"
03860             "State: %s\r\n"
03861             "CallerID: %s\r\n"
03862             "CallerIDName: %s\r\n"
03863             "Uniqueid: %s\r\n",
03864             chan->name, ast_state2str(chan->_state),
03865             S_OR(chan->cid.cid_num, "<unknown>"),
03866             S_OR(chan->cid.cid_name, "<unknown>"),
03867             chan->uniqueid);
03868 
03869    return 0;
03870 }

int ast_settimeout ( struct ast_channel c,
int  samples,
int(*)(void *data)  func,
void *  data 
)

Definition at line 2062 of file channel.c.

References ast_log(), func, LOG_DEBUG, option_debug, ast_channel::timingdata, ast_channel::timingfd, and ast_channel::timingfunc.

02063 {
02064    int res = -1;
02065 #ifdef HAVE_ZAPTEL
02066    if (c->timingfd > -1) {
02067       if (!func) {
02068          samples = 0;
02069          data = 0;
02070       }
02071       if (option_debug)
02072          ast_log(LOG_DEBUG, "Scheduling timer at %d sample intervals\n", samples);
02073       res = ioctl(c->timingfd, ZT_TIMERCONFIG, &samples);
02074       c->timingfunc = func;
02075       c->timingdata = data;
02076    }
02077 #endif   
02078    return res;
02079 }

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 480 of file channel.c.

References shutting_down.

00481 {
00482    return shutting_down;
00483 }

int ast_softhangup ( struct ast_channel chan,
int  cause 
)

Softly hangup up a channel.

Parameters:
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
Returns:
Returns 0 regardless

Definition at line 1558 of file channel.c.

References ast_channel_lock, ast_channel_unlock, and ast_softhangup_nolock().

01559 {
01560    int res;
01561    ast_channel_lock(chan);
01562    res = ast_softhangup_nolock(chan, cause);
01563    ast_channel_unlock(chan);
01564    return res;
01565 }

int ast_softhangup_nolock ( struct ast_channel chan,
int  cause 
)

Softly hangup up a channel (no channel lock).

Parameters:
chan channel to be soft-hung-up
cause Ast hangupcause for hangup (see cause.h)

Definition at line 1544 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, LOG_DEBUG, and option_debug.

01545 {
01546    if (option_debug)
01547       ast_log(LOG_DEBUG, "Soft-Hanging up channel '%s'\n", chan->name);
01548    /* Inform channel driver that we need to be hung up, if it cares */
01549    chan->_softhangup |= cause;
01550    ast_queue_frame(chan, &ast_null_frame);
01551    /* Interrupt any poll call or such */
01552    if (ast_test_flag(chan, AST_FLAG_BLOCKING))
01553       pthread_kill(chan->blocker, SIGURG);
01554    return 0;
01555 }

char* ast_state2str ( enum  ast_channel_state  ) 

Gives the string form of a given channel state.

Gives the string form of a given channel state

Parameters:
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 619 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.

00620 {
00621    char *buf;
00622 
00623    switch(state) {
00624    case AST_STATE_DOWN:
00625       return "Down";
00626    case AST_STATE_RESERVED:
00627       return "Rsrvd";
00628    case AST_STATE_OFFHOOK:
00629       return "OffHook";
00630    case AST_STATE_DIALING:
00631       return "Dialing";
00632    case AST_STATE_RING:
00633       return "Ring";
00634    case AST_STATE_RINGING:
00635       return "Ringing";
00636    case AST_STATE_UP:
00637       return "Up";
00638    case AST_STATE_BUSY:
00639       return "Busy";
00640    case AST_STATE_DIALING_OFFHOOK:
00641       return "Dialing Offhook";
00642    case AST_STATE_PRERING:
00643       return "Pre-ring";
00644    default:
00645       if (!(buf = ast_threadstorage_get(&state2str_threadbuf, STATE2STR_BUFSIZE)))
00646          return "Unknown";
00647       snprintf(buf, STATE2STR_BUFSIZE, "Unknown (%d)", state);
00648       return buf;
00649    }
00650 }

int ast_str2cause ( const char *  name  ) 

Convert a symbolic hangup cause to number.

Convert the string form of a cause code to a number

Parameters:
name string form of the cause Returns the cause code

Definition at line 607 of file channel.c.

References causes.

00608 {
00609    int x;
00610 
00611    for (x = 0; x < sizeof(causes) / sizeof(causes[0]); x++)
00612       if (strncasecmp(causes[x].name, name, strlen(causes[x].name)) == 0)
00613          return causes[x].cause;
00614 
00615    return -1;
00616 }

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 4476 of file channel.c.

References ast_frfree(), ast_read(), ast_tonepair_start(), ast_waitfor(), f, and ast_channel::generatordata.

04477 {
04478    int res;
04479 
04480    if ((res = ast_tonepair_start(chan, freq1, freq2, duration, vol)))
04481       return res;
04482 
04483    /* Give us some wiggle room */
04484    while (chan->generatordata && ast_waitfor(chan, 100) >= 0) {
04485       struct ast_frame *f = ast_read(chan);
04486       if (f)
04487          ast_frfree(f);
04488       else
04489          return -1;
04490    }
04491    return 0;
04492 }

int ast_tonepair_start ( struct ast_channel chan,
int  freq1,
int  freq2,
int  duration,
int  vol 
)

Start a tone going

Definition at line 4458 of file channel.c.

References ast_activate_generator(), tonepair_def::duration, tonepair_def::freq1, tonepair_def::freq2, tonepair, and tonepair_def::vol.

04459 {
04460    struct tonepair_def d = { 0, };
04461 
04462    d.freq1 = freq1;
04463    d.freq2 = freq2;
04464    d.duration = duration;
04465    d.vol = (vol < 1) ? 8192 : vol; /* force invalid to 8192 */
04466    if (ast_activate_generator(chan, &tonepair, &d))
04467       return -1;
04468    return 0;
04469 }

void ast_tonepair_stop ( struct ast_channel chan  ) 

Stop a tone from playing

Definition at line 4471 of file channel.c.

References ast_deactivate_generator().

04472 {
04473    ast_deactivate_generator(chan);
04474 }

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.

Parameters:
chan current channel
dest destination extension for transfer
Transfer a channel (if supported). Returns -1 on error, 0 if not supported and 1 if supported and requested.

Called by:

Definition at line 3240 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.

03241 {
03242    int res = -1;
03243 
03244    /* Stop if we're a zombie or need a soft hangup */
03245    ast_channel_lock(chan);
03246    if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {
03247       if (chan->tech->transfer) {
03248          res = chan->tech->transfer(chan, dest);
03249          if (!res)
03250             res = 1;
03251       } else
03252          res = 0;
03253    }
03254    ast_channel_unlock(chan);
03255    return res;
03256 }

char* ast_transfercapability2str ( int  transfercapability  )  const

Gives the string form of a given transfer capability.

Gives the string form of a given transfer capability

Parameters:
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 653 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.

00654 {
00655    switch(transfercapability) {
00656    case AST_TRANS_CAP_SPEECH:
00657       return "SPEECH";
00658    case AST_TRANS_CAP_DIGITAL:
00659       return "DIGITAL";
00660    case AST_TRANS_CAP_RESTRICTED_DIGITAL:
00661       return "RESTRICTED_DIGITAL";
00662    case AST_TRANS_CAP_3_1K_AUDIO:
00663       return "3K1AUDIO";
00664    case AST_TRANS_CAP_DIGITAL_W_TONES:
00665       return "DIGITAL_W_TONES";
00666    case AST_TRANS_CAP_VIDEO:
00667       return "VIDEO";
00668    default:
00669       return "UNKNOWN";
00670    }
00671 }

int ast_waitfor ( struct ast_channel chan,
int  ms 
)

Wait for input on a channel.

Parameters:
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).
Returns:
Returns < 0 on failure, 0 if nothing ever arrived, and the # of ms remaining otherwise

Definition at line 2046 of file channel.c.

References ast_waitfor_nandfds().

02047 {
02048    int oldms = ms;   /* -1 if no timeout */
02049 
02050    ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms);
02051    if ((ms < 0) && (oldms < 0))
02052       ms = 0;
02053    return ms;
02054 }

struct ast_channel* ast_waitfor_n ( struct ast_channel **  chan,
int  n,
int *  ms 
) [read]

Waits for input on a group of channels Wait for input on an array of channels for a given # of milliseconds.

Returns:
Return channel with activity, or NULL if none has activity.
Parameters:
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 2041 of file channel.c.

References ast_waitfor_nandfds().

02042 {
02043    return ast_waitfor_nandfds(c, n, NULL, 0, NULL, NULL, ms);
02044 }

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 1886 of file channel.c.

References ast_waitfor_nandfds().

01887 {
01888    int winner = -1;
01889    ast_waitfor_nandfds(NULL, 0, fds, n, exception, &winner, ms);
01890    return winner;
01891 }

struct ast_channel* ast_waitfor_nandfds ( struct ast_channel **  c,
int  n,
int *  fds,
int  nfds,
int *  exception,
int *  outfd,
int *  ms 
) [read]

Waits for activity on a group of channels.

Parameters:
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.
Returns:
Returns the channel with activity, or NULL on error or if an FD came first. If the FD came first, it will be returned in outfd, otherwise, outfd will be -1

Definition at line 1894 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, pollfd::fd, ast_channel::fdno, LOG_WARNING, poll(), POLLPRI, pollfd::revents, and ast_channel::whentohangup.

01896 {
01897    struct timeval start = { 0 , 0 };
01898    struct pollfd *pfds;
01899    int res;
01900    long rms;
01901    int x, y, max;
01902    int sz;
01903    time_t now = 0;
01904    long whentohangup = 0, diff;
01905    struct ast_channel *winner = NULL;
01906    struct fdmap {
01907       int chan;
01908       int fdno;
01909    } *fdmap;
01910 
01911    sz = n * AST_MAX_FDS + nfds;
01912    pfds = alloca(sizeof(*pfds) * sz);
01913    fdmap = alloca(sizeof(*fdmap) * sz);
01914 
01915    if (outfd)
01916       *outfd = -99999;
01917    if (exception)
01918       *exception = 0;
01919    
01920    /* Perform any pending masquerades */
01921    for (x=0; x < n; x++) {
01922       ast_channel_lock(c[x]);
01923       if (c[x]->masq) {
01924          if (ast_do_masquerade(c[x])) {
01925             ast_log(LOG_WARNING, "Masquerade failed\n");
01926             *ms = -1;
01927             ast_channel_unlock(c[x]);
01928             return NULL;
01929          }
01930       }
01931       if (c[x]->whentohangup) {
01932          if (!whentohangup)
01933             time(&now);
01934          diff = c[x]->whentohangup - now;
01935          if (diff < 1) {
01936             /* Should already be hungup */
01937             c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
01938             ast_channel_unlock(c[x]);
01939             return c[x];
01940          }
01941          if (!whentohangup || (diff < whentohangup))
01942             whentohangup = diff;
01943       }
01944       ast_channel_unlock(c[x]);
01945    }
01946    /* Wait full interval */
01947    rms = *ms;
01948    if (whentohangup) {
01949       rms = whentohangup * 1000;              /* timeout in milliseconds */
01950       if (*ms >= 0 && *ms < rms)    /* original *ms still smaller */
01951          rms =  *ms;
01952    }
01953    /*
01954     * Build the pollfd array, putting the channels' fds first,
01955     * followed by individual fds. Order is important because
01956     * individual fd's must have priority over channel fds.
01957     */
01958    max = 0;
01959    for (x=0; x<n; x++) {
01960       for (y=0; y<AST_MAX_FDS; y++) {
01961          fdmap[max].fdno = y;  /* fd y is linked to this pfds */
01962          fdmap[max].chan = x;  /* channel x is linked to this pfds */
01963          max += ast_add_fd(&pfds[max], c[x]->fds[y]);
01964       }
01965       CHECK_BLOCKING(c[x]);
01966    }
01967    /* Add the individual fds */
01968    for (x=0; x<nfds; x++) {
01969       fdmap[max].chan = -1;
01970       max += ast_add_fd(&pfds[max], fds[x]);
01971    }
01972 
01973    if (*ms > 0)
01974       start = ast_tvnow();
01975    
01976    if (sizeof(int) == 4) { /* XXX fix timeout > 600000 on linux x86-32 */
01977       do {
01978          int kbrms = rms;
01979          if (kbrms > 600000)
01980             kbrms = 600000;
01981          res = poll(pfds, max, kbrms);
01982          if (!res)
01983             rms -= kbrms;
01984       } while (!res && (rms > 0));
01985    } else {
01986       res = poll(pfds, max, rms);
01987    }
01988    for (x=0; x<n; x++)
01989       ast_clear_flag(c[x], AST_FLAG_BLOCKING);
01990    if (res < 0) { /* Simulate a timeout if we were interrupted */
01991       if (errno != EINTR)
01992          *ms = -1;
01993       return NULL;
01994    }
01995    if (whentohangup) {   /* if we have a timeout, check who expired */
01996       time(&now);
01997       for (x=0; x<n; x++) {
01998          if (c[x]->whentohangup && now >= c[x]->whentohangup) {
01999             c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
02000             if (winner == NULL)
02001                winner = c[x];
02002          }
02003       }
02004    }
02005    if (res == 0) { /* no fd ready, reset timeout and done */
02006       *ms = 0; /* XXX use 0 since we may not have an exact timeout. */
02007       return winner;
02008    }
02009    /*
02010     * Then check if any channel or fd has a pending event.
02011     * Remember to check channels first and fds last, as they
02012     * must have priority on setting 'winner'
02013     */
02014    for (x = 0; x < max; x++) {
02015       res = pfds[x].revents;
02016       if (res == 0)
02017          continue;
02018       if (fdmap[x].chan >= 0) {  /* this is a channel */
02019          winner = c[fdmap[x].chan]; /* override previous winners */
02020          if (res & POLLPRI)
02021             ast_set_flag(winner, AST_FLAG_EXCEPTION);
02022          else
02023             ast_clear_flag(winner, AST_FLAG_EXCEPTION);
02024          winner->fdno = fdmap[x].fdno;
02025       } else {       /* this is an fd */
02026          if (outfd)
02027             *outfd = pfds[x].fd;
02028          if (exception)
02029             *exception = (res & POLLPRI) ? -1 : 0;
02030          winner = NULL;
02031       }
02032    }
02033    if (*ms > 0) {
02034       *ms -= ast_tvdiff_ms(ast_tvnow(), start);
02035       if (*ms < 0)
02036          *ms = 0;
02037    }
02038    return winner;
02039 }

int ast_waitfordigit ( struct ast_channel c,
int  ms 
)

Waits for a digit.

!

Parameters:
c channel to wait for a digit on
ms how many milliseconds to wait
Returns:
Returns <0 on error, 0 on no entry, and the digit on success.

Definition at line 2057 of file channel.c.

References ast_waitfordigit_full().

02058 {
02059    return ast_waitfordigit_full(c, ms, -1, -1);
02060 }

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.

Parameters:
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
Returns:
Returns 1 if ctrlfd becomes available

Definition at line 2081 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_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_VOICE, ast_frfree(), ast_log(), ast_read(), ast_test_flag, ast_waitfor_nandfds(), ast_frame::data, ast_frame::datalen, f, ast_frame::frametype, LOG_WARNING, and ast_frame::subclass.

02082 {
02083    int begin_digit = 0;
02084 
02085    /* Stop if we're a zombie or need a soft hangup */
02086    if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
02087       return -1;
02088    /* Wait for a digit, no more than ms milliseconds total. */
02089    while (ms) {
02090       struct ast_channel *rchan;
02091       int outfd;
02092 
02093       errno = 0;
02094       rchan = ast_waitfor_nandfds(&c, 1, &cmdfd, (cmdfd > -1) ? 1 : 0, NULL, &outfd, &ms);
02095       if (!rchan && outfd < 0 && ms) {
02096          if (errno == 0 || errno == EINTR)
02097             continue;
02098          ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno));
02099          return -1;
02100       } else if (outfd > -1) {
02101          /* The FD we were watching has something waiting */
02102          return 1;
02103       } else if (rchan) {
02104          int res;
02105          struct ast_frame *f = ast_read(c);
02106          if (!f)
02107             return -1;
02108 
02109          switch(f->frametype) {
02110          case AST_FRAME_DTMF_BEGIN:
02111             begin_digit = f->subclass;
02112             break;
02113          case AST_FRAME_DTMF_END:
02114             if (begin_digit != f->subclass)
02115                break;
02116             res = f->subclass;
02117             ast_frfree(f);
02118             return res;
02119          case AST_FRAME_CONTROL:
02120             switch(f->subclass) {
02121             case AST_CONTROL_HANGUP:
02122                ast_frfree(f);
02123                return -1;
02124             case AST_CONTROL_RINGING:
02125             case AST_CONTROL_ANSWER:
02126                /* Unimportant */
02127                break;
02128             default:
02129                ast_log(LOG_WARNING, "Unexpected control subclass '%d'\n", f->subclass);
02130                break;
02131             }
02132             break;
02133          case AST_FRAME_VOICE:
02134             /* Write audio if appropriate */
02135             if (audiofd > -1)
02136                write(audiofd, f->data, f->datalen);
02137          default:
02138             /* Ignore */
02139             break;
02140          }
02141          ast_frfree(f);
02142       }
02143    }
02144    return 0; /* Time is up */
02145 }

struct ast_channel* ast_walk_channel_by_exten_locked ( const struct ast_channel chan,
const char *  exten,
const char *  context 
) [read]

Get next channel by exten (and optionally context) and lock it.

Definition at line 1142 of file channel.c.

References channel_find_locked().

01144 {
01145    return channel_find_locked(chan, NULL, 0, context, exten);
01146 }

struct ast_channel* ast_walk_channel_by_name_prefix_locked ( const struct ast_channel chan,
const char *  name,
const int  namelen 
) [read]

Get channel by name prefix (locks channel).

Definition at line 1129 of file channel.c.

References channel_find_locked().

01131 {
01132    return channel_find_locked(chan, name, namelen, NULL, NULL);
01133 }

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.

Parameters:
chan destination channel of the frame
frame frame that will be written
Returns:
It returns 0 on success, -1 on failure.

Todo:
XXX should return 0 maybe ?

Definition at line 2769 of file channel.c.

References ast_channel::_softhangup, ast_channel_lock, ast_channel_unlock, ast_check_hangup(), ast_clear_flag, AST_CONTROL_UNHOLD, 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, ast_channel_whisper_buffer::original_format, ast_channel::outsmpl, ast_channel_whisper_buffer::path, queue_frame_to_spies(), ast_channel::rawwriteformat, ast_frame::samples, 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.

02770 {
02771    int res = -1;
02772    struct ast_frame *f = NULL;
02773 
02774    /* Stop if we're a zombie or need a soft hangup */
02775    ast_channel_lock(chan);
02776    if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
02777       goto done;
02778 
02779    /* Handle any pending masquerades */
02780    if (chan->masq && ast_do_masquerade(chan)) {
02781       ast_log(LOG_WARNING, "Failed to perform masquerade\n");
02782       goto done;
02783    }
02784    if (chan->masqr) {
02785       res = 0; /* XXX explain, why 0 ? */
02786       goto done;
02787    }
02788    if (chan->generatordata) {
02789       if (ast_test_flag(chan, AST_FLAG_WRITE_INT))
02790          ast_deactivate_generator(chan);
02791       else {
02792          if (fr->frametype == AST_FRAME_DTMF_END) {
02793             /* There is a generator running while we're in the middle of a digit.
02794              * It's probably inband DTMF, so go ahead and pass it so it can
02795              * stop the generator */
02796             ast_clear_flag(chan, AST_FLAG_BLOCKING);
02797             ast_channel_unlock(chan);
02798             res = ast_senddigit_end(chan, fr->subclass, fr->len);
02799             ast_channel_lock(chan);
02800             CHECK_BLOCKING(chan);
02801          } else if (fr->frametype == AST_FRAME_CONTROL && fr->subclass == AST_CONTROL_UNHOLD) {
02802             /* This is a side case where Echo is basically being called and the person put themselves on hold and took themselves off hold */
02803             res = (chan->tech->indicate == NULL) ? 0 :
02804                chan->tech->indicate(chan, fr->subclass, fr->data, fr->datalen);
02805          }
02806          res = 0; /* XXX explain, why 0 ? */
02807          goto done;
02808       }
02809    }
02810    /* High bit prints debugging */
02811    if (chan->fout & DEBUGCHAN_FLAG)
02812       ast_frame_dump(chan->name, fr, ">>");
02813    CHECK_BLOCKING(chan);
02814    switch(fr->frametype) {
02815    case AST_FRAME_CONTROL:
02816       res = (chan->tech->indicate == NULL) ? 0 :
02817          chan->tech->indicate(chan, fr->subclass, fr->data, fr->datalen);
02818       break;
02819    case AST_FRAME_DTMF_BEGIN:
02820       ast_clear_flag(chan, AST_FLAG_BLOCKING);
02821       ast_channel_unlock(chan);
02822       res = ast_senddigit_begin(chan, fr->subclass);
02823       ast_channel_lock(chan);
02824       CHECK_BLOCKING(chan);
02825       break;
02826    case AST_FRAME_DTMF_END:
02827       ast_clear_flag(chan, AST_FLAG_BLOCKING);
02828       ast_channel_unlock(chan);
02829       res = ast_senddigit_end(chan, fr->subclass, fr->len);
02830       ast_channel_lock(chan);
02831       CHECK_BLOCKING(chan);
02832       break;
02833    case AST_FRAME_TEXT:
02834       res = (chan->tech->send_text == NULL) ? 0 :
02835          chan->tech->send_text(chan, (char *) fr->data);
02836       break;
02837    case AST_FRAME_HTML:
02838       res = (chan->tech->send_html == NULL) ? 0 :
02839          chan->tech->send_html(chan, fr->subclass, (char *) fr->data, fr->datalen);
02840       break;
02841    case AST_FRAME_VIDEO:
02842       /* XXX Handle translation of video codecs one day XXX */
02843       res = (chan->tech->write_video == NULL) ? 0 :
02844          chan->tech->write_video(chan, fr);
02845       break;
02846    case AST_FRAME_MODEM:
02847       res = (chan->tech->write == NULL) ? 0 :
02848          chan->tech->write(chan, fr);
02849       break;
02850    case AST_FRAME_VOICE:
02851       if (chan->tech->write == NULL)
02852          break;   /*! \todo XXX should return 0 maybe ? */
02853 
02854       /* If someone is whispering on this channel then we must ensure that we are always getting signed linear frames */
02855       if (ast_test_flag(chan, AST_FLAG_WHISPER)) {
02856          if (fr->subclass == AST_FORMAT_SLINEAR)
02857             f = fr;
02858          else {
02859             ast_mutex_lock(&chan->whisper->lock);
02860             if (chan->writeformat != AST_FORMAT_SLINEAR) {
02861                /* Rebuild the translation path and set our write format back to signed linear */
02862                chan->whisper->original_format = chan->writeformat;
02863                ast_set_write_format(chan, AST_FORMAT_SLINEAR);
02864                if (chan->whisper->path)
02865                   ast_translator_free_path(chan->whisper->path);
02866                chan->whisper->path = ast_translator_build_path(AST_FORMAT_SLINEAR, chan->whisper->original_format);
02867             }
02868             /* Translate frame using the above translation path */
02869             f = (chan->whisper->path) ? ast_translate(chan->whisper->path, fr, 0) : fr;
02870             ast_mutex_unlock(&chan->whisper->lock);
02871          }
02872       } else {
02873          /* If the frame is in the raw write format, then it's easy... just use the frame - otherwise we will have to translate */
02874          if (fr->subclass == chan->rawwriteformat)
02875             f = fr;
02876          else
02877             f = (chan->writetrans) ? ast_translate(chan->writetrans, fr, 0) : fr;
02878       }
02879 
02880       /* If we have no frame of audio, then we have to bail out */
02881       if (f == NULL) {
02882          res = 0;
02883          break;
02884       }
02885 
02886       /* If spies are on the channel then queue the frame out to them */
02887       if (chan->spies)
02888          queue_frame_to_spies(chan, f, SPY_WRITE);
02889 
02890       /* If Monitor is running on this channel, then we have to write frames out there too */
02891       if (chan->monitor && chan->monitor->write_stream) {
02892          /* XXX must explain this code */
02893 #ifndef MONITOR_CONSTANT_DELAY
02894          int jump = chan->insmpl - chan->outsmpl - 4 * f->samples;
02895          if (jump >= 0) {
02896             jump = chan->insmpl - chan->outsmpl;
02897             if (ast_seekstream(chan->monitor->write_stream, jump, SEEK_FORCECUR) == -1)
02898                ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
02899             chan->outsmpl += jump + f->samples;
02900          } else
02901             chan->outsmpl += f->samples;
02902 #else
02903          int jump = chan->insmpl - chan->outsmpl;
02904          if (jump - MONITOR_DELAY >= 0) {
02905             if (ast_seekstream(chan->monitor->write_stream, jump - f->samples, SEEK_FORCECUR) == -1)
02906                ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
02907             chan->outsmpl += jump;
02908          } else
02909             chan->outsmpl += f->samples;
02910 #endif
02911          if (chan->monitor->state == AST_MONITOR_RUNNING) {
02912             if (ast_writestream(chan->monitor->write_stream, f) < 0)
02913                ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n");
02914          }
02915       }
02916 
02917       /* Finally the good part! Write this out to the channel */
02918       if (ast_test_flag(chan, AST_FLAG_WHISPER)) {
02919          /* frame is assumed to be in SLINEAR, since that is
02920             required for whisper mode */
02921          ast_frame_adjust_volume(f, -2);
02922          if (ast_slinfactory_available(&chan->whisper->sf) >= f->samples) {
02923             short buf[f->samples];
02924             struct ast_frame whisper = {
02925                .frametype = AST_FRAME_VOICE,
02926                .subclass = AST_FORMAT_SLINEAR,
02927                .data = buf,
02928                .datalen = sizeof(buf),
02929                .samples = f->samples,
02930             };
02931             
02932             ast_mutex_lock(&chan->whisper->lock);
02933             if (ast_slinfactory_read(&chan->whisper->sf, buf, f->samples))
02934                ast_frame_slinear_sum(f, &whisper);
02935             ast_mutex_unlock(&chan->whisper->lock);
02936          }
02937          /* and now put it through the regular translator */
02938          f = (chan->writetrans) ? ast_translate(chan->writetrans, f, 0) : f;
02939       }
02940       if (f)
02941          res = chan->tech->write(chan, f);
02942       else
02943          res = 0;
02944       break;
02945    case AST_FRAME_NULL:
02946    case AST_FRAME_IAX:
02947       /* Ignore these */
02948       res = 0;
02949       break;
02950    default:
02951       /* At this point, fr is the incoming frame and f is NULL.  Channels do
02952        * not expect to get NULL as a frame pointer and will segfault.  Hence,
02953        * we output the original frame passed in. */
02954       res = chan->tech->write(chan, fr);
02955       break;
02956    }
02957 
02958    if (f && f != fr)
02959       ast_frfree(f);
02960    ast_clear_flag(chan, AST_FLAG_BLOCKING);
02961    /* Consider a write failure to force a soft hangup */
02962    if (res < 0)
02963       chan->_softhangup |= AST_SOFTHANGUP_DEV;
02964    else {
02965       chan->fout = FRAMECOUNT_INC(chan->fout);
02966    }
02967 done:
02968    ast_channel_unlock(chan);
02969    return res;
02970 }

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.

Parameters:
chan destination channel of the frame
frame frame that will be written
Returns:
It returns 1 on success, 0 if not implemented, and -1 on failure.

Definition at line 2758 of file channel.c.

References ast_write(), ast_channel::tech, and ast_channel_tech::write_video.

02759 {
02760    int res;
02761    if (!chan->tech->write_video)
02762       return 0;
02763    res = ast_write(chan, fr);
02764    if (!res)
02765       res = 1;
02766    return res;
02767 }

const char* channelreloadreason2txt ( enum channelreloadreason  reason  ) 

Convert enum channelreloadreason to text string for manager event.

Parameters:
reason Enum channelreloadreason - reason for reload (manager, cli, start etc)
\ brief Convert channel reloadreason (ENUM) to text string for manager event

Definition at line 4811 of file channel.c.

References CHANNEL_CLI_RELOAD, CHANNEL_MODULE_LOAD, and CHANNEL_MODULE_RELOAD.

04812 {
04813    switch (reason) {
04814    case CHANNEL_MODULE_LOAD:
04815       return "LOAD (Channel module load)";
04816 
04817    case CHANNEL_MODULE_RELOAD:
04818       return "RELOAD (Channel module reload)";
04819 
04820    case CHANNEL_CLI_RELOAD:
04821       return "CLIRELOAD (Channel module reload by CLI command)";
04822 
04823    default:
04824       return "MANAGERRELOAD (Channel module reload by manager)";
04825    }
04826 };


Generated on Wed Aug 15 01:25:00 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.3