Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:00:46 2007

Asterisk developer's documentation :: Codename Pineapple


channel.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2006, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  * \brief General Asterisk PBX channel definitions.
00021  * \par See also:
00022  *  \arg \ref Def_Channel
00023  *  \arg \ref channel_drivers
00024  */
00025 
00026 /*! \page Def_Channel Asterisk Channels
00027    \par What is a Channel?
00028    A phone call through Asterisk consists of an incoming
00029    connection and an outbound connection. Each call comes
00030    in through a channel driver that supports one technology,
00031    like SIP, ZAP, IAX2 etc. 
00032    \par
00033    Each channel driver, technology, has it's own private
00034    channel or dialog structure, that is technology-dependent.
00035    Each private structure is "owned" by a generic Asterisk
00036    channel structure, defined in channel.h and handled by
00037    channel.c .
00038    \par Call scenario
00039    This happens when an incoming call arrives to Asterisk
00040    -# Call arrives on a channel driver interface
00041    -# Channel driver creates a PBX channel and starts a 
00042       pbx thread on the channel
00043    -# The dial plan is executed
00044    -# At this point at least two things can happen:
00045       -# The call is answered by Asterisk and 
00046          Asterisk plays a media stream or reads media
00047       -# The dial plan forces Asterisk to create an outbound 
00048          call somewhere with the dial (see \ref app_dial.c)
00049          application
00050    .
00051 
00052    \par Bridging channels
00053    If Asterisk dials out this happens:
00054    -# Dial creates an outbound PBX channel and asks one of the
00055       channel drivers to create a call
00056    -# When the call is answered, Asterisk bridges the media streams
00057       so the caller on the first channel can speak with the callee
00058       on the second, outbound channel
00059    -# In some cases where we have the same technology on both
00060       channels and compatible codecs, a native bridge is used.
00061       In a native bridge, the channel driver handles forwarding
00062       of incoming audio to the outbound stream internally, without
00063       sending audio frames through the PBX.
00064    -# In SIP, theres an "external native bridge" where Asterisk
00065       redirects the endpoint, so audio flows directly between the
00066       caller's phone and the callee's phone. Signalling stays in
00067       Asterisk in order to be able to provide a proper CDR record
00068       for the call.
00069 
00070    
00071    \par Masquerading channels
00072    In some cases, a channel can masquerade itself into another
00073    channel. This happens frequently in call transfers, where 
00074    a new channel takes over a channel that is already involved
00075    in a call. The new channel sneaks in and takes over the bridge
00076    and the old channel, now a zombie, is hung up.
00077    
00078    \par Reference
00079    \arg channel.c - generic functions
00080    \arg channel.h - declarations of functions, flags and structures
00081    \arg translate.h - Transcoding support functions
00082    \arg \ref channel_drivers - Implemented channel drivers
00083    \arg \ref Def_Frame Asterisk Multimedia Frames
00084    \arg \ref Def_Bridge
00085 
00086 */
00087 /*! \page Def_Bridge Asterisk Channel Bridges
00088 
00089    In Asterisk, there's several media bridges. 
00090 
00091    The Core bridge handles two channels (a "phone call") and bridge
00092    them together.
00093    
00094    The conference bridge (meetme) handles several channels simultaneously
00095    with the support of an external timer (zaptel timer). This is used
00096    not only by the Conference application (meetme) but also by the
00097    page application and the SLA system introduced in 1.4.
00098    The conference bridge does not handle video.
00099 
00100    When two channels of the same type connect, the channel driver
00101    or the media subsystem used by the channel driver (i.e. RTP)
00102    can create a native bridge without sending media through the
00103    core.
00104 
00105    Native briding can be disabled by a number of reasons,
00106    like DTMF being needed by the core or codecs being incompatible
00107    so a transcoding module is needed.
00108 
00109 References:
00110         - ast_channel_early_bridge()
00111         - ast_channel_bridge()
00112    - app_meetme.c
00113    - \ref AstRTPbridge
00114         - ast_rtp_bridge() 
00115    - \ref Def_Channel
00116 */
00117 
00118 /*! \page AstFileDesc File descriptors 
00119    Asterisk File descriptors are connected to each channel (see \ref Def_Channel)
00120    in the \ref ast_channel structure.
00121 */
00122 
00123 #ifndef _ASTERISK_CHANNEL_H
00124 #define _ASTERISK_CHANNEL_H
00125 
00126 #include "asterisk/abstract_jb.h"
00127 
00128 #include <unistd.h>
00129 #ifdef POLLCOMPAT 
00130 #include "asterisk/poll-compat.h"
00131 #else
00132 #include <sys/poll.h>
00133 #endif
00134 
00135 #if defined(__cplusplus) || defined(c_plusplus)
00136 extern "C" {
00137 #endif
00138 
00139 #define AST_MAX_EXTENSION  80 /*!< Max length of an extension */
00140 #define AST_MAX_CONTEXT    80 /*!< Max length of a context */
00141 #define AST_CHANNEL_NAME   80 /*!< Max length of an ast_channel name */
00142 #define MAX_LANGUAGE    20 /*!< Max length of the language setting */
00143 #define MAX_MUSICCLASS     80 /*!< Max length of the music class setting */
00144 
00145 #include "asterisk/compat.h"
00146 #include "asterisk/frame.h"
00147 #include "asterisk/sched.h"
00148 #include "asterisk/chanvars.h"
00149 #include "asterisk/config.h"
00150 #include "asterisk/lock.h"
00151 #include "asterisk/cdr.h"
00152 #include "asterisk/utils.h"
00153 #include "asterisk/linkedlists.h"
00154 #include "asterisk/stringfields.h"
00155 #include "asterisk/compiler.h"
00156 
00157 
00158 #define AST_MAX_FDS     8
00159 /*
00160  * We have AST_MAX_FDS file descriptors in a channel.
00161  * Some of them have a fixed use:
00162  */
00163 #define AST_ALERT_FD (AST_MAX_FDS-1)      /*!< used for alertpipe */
00164 #define AST_TIMING_FD   (AST_MAX_FDS-2)      /*!< used for timingfd */
00165 #define AST_AGENT_FD (AST_MAX_FDS-3)      /*!< used by agents for pass through */
00166 #define AST_GENERATOR_FD   (AST_MAX_FDS-4)   /*!< used by generator */
00167 
00168 enum ast_bridge_result {
00169    AST_BRIDGE_COMPLETE = 0,
00170    AST_BRIDGE_FAILED = -1,
00171    AST_BRIDGE_FAILED_NOWARN = -2,
00172    AST_BRIDGE_RETRY = -3,
00173 };
00174 
00175 typedef unsigned long long ast_group_t;
00176 
00177 /*! \todo Add an explanation of an Asterisk generator 
00178 */
00179 struct ast_generator {
00180    void *(*alloc)(struct ast_channel *chan, void *params);
00181    void (*release)(struct ast_channel *chan, void *data);
00182    int (*generate)(struct ast_channel *chan, void *data, int len, int samples);
00183 };
00184 
00185 /*! \brief Structure for a data store type */
00186 struct ast_datastore_info {
00187    const char *type;    /*!< Type of data store */
00188    void (*destroy)(void *data);  /*!< Destroy function */
00189 };
00190 
00191 /*! \brief Structure for a channel data store */
00192 struct ast_datastore {
00193    char *uid;     /*!< Unique data store identifier */
00194    void *data;    /*!< Contained data */
00195    const struct ast_datastore_info *info; /*!< Data store type information */
00196    AST_LIST_ENTRY(ast_datastore) entry; /*!< Used for easy linking */
00197 };
00198 
00199 /*! \brief Structure for all kinds of caller ID identifications.
00200  * \note All string fields here are malloc'ed, so they need to be
00201  * freed when the structure is deleted.
00202  * Also, NULL and "" must be considered equivalent.
00203  */
00204 struct ast_callerid {
00205    char *cid_dnid;      /*!< Malloc'd Dialed Number Identifier */
00206    char *cid_num;    /*!< Malloc'd Caller Number */
00207    char *cid_name;      /*!< Malloc'd Caller Name */
00208    char *cid_ani;    /*!< Malloc'd ANI */
00209    char *cid_rdnis;  /*!< Malloc'd RDNIS */
00210    int cid_pres;     /*!< Callerid presentation/screening */
00211    int cid_ani2;     /*!< Callerid ANI 2 (Info digits) */
00212    int cid_ton;      /*!< Callerid Type of Number */
00213    int cid_tns;      /*!< Callerid Transit Network Select */
00214 };
00215 
00216 /*! \brief 
00217    Structure to describe a channel "technology", ie a channel driver 
00218    See for examples:
00219    \arg chan_iax2.c - The Inter-Asterisk exchange protocol
00220    \arg chan_sip.c - The SIP channel driver
00221    \arg chan_zap.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS)
00222 
00223    If you develop your own channel driver, this is where you
00224    tell the PBX at registration of your driver what properties
00225    this driver supports and where different callbacks are 
00226    implemented.
00227 */
00228 struct ast_channel_tech {
00229    const char * const type;
00230    const char * const description;
00231 
00232    int capabilities;    /*!< Bitmap of formats this channel can handle */
00233 
00234    int properties;         /*!< Technology Properties */
00235 
00236    /*! \brief Requester - to set up call data structures (pvt's) */
00237    struct ast_channel *(* const requester)(const char *type, int format, void *data, int *cause);
00238 
00239    int (* const devicestate)(void *data); /*!< Devicestate call back */
00240 
00241    /*! \brief Start sending a literal DTMF digit */
00242    int (* const send_digit_begin)(struct ast_channel *chan, char digit);
00243 
00244    /*! \brief Stop sending a literal DTMF digit */
00245    int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration);
00246 
00247    /*! \brief Call a given phone number (address, etc), but don't
00248       take longer than timeout seconds to do so.  */
00249    int (* const call)(struct ast_channel *chan, char *addr, int timeout);
00250 
00251    /*! \brief Hangup (and possibly destroy) the channel */
00252    int (* const hangup)(struct ast_channel *chan);
00253 
00254    /*! \brief Answer the channel */
00255    int (* const answer)(struct ast_channel *chan);
00256 
00257    /*! \brief Read a frame, in standard format (see frame.h) */
00258    struct ast_frame * (* const read)(struct ast_channel *chan);
00259 
00260    /*! \brief Write a frame, in standard format (see frame.h) */
00261    int (* const write)(struct ast_channel *chan, struct ast_frame *frame);
00262 
00263    /*! \brief Display or transmit text */
00264    int (* const send_text)(struct ast_channel *chan, const char *text);
00265 
00266    /*! \brief Display or send an image */
00267    int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame);
00268 
00269    /*! \brief Send HTML data */
00270    int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len);
00271 
00272    /*! \brief Handle an exception, reading a frame */
00273    struct ast_frame * (* const exception)(struct ast_channel *chan);
00274 
00275    /*! \brief Bridge two channels of the same type together */
00276    enum ast_bridge_result (* const bridge)(struct ast_channel *c0, struct ast_channel *c1, int flags,
00277                   struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
00278 
00279    /*! \brief Bridge two channels of the same type together (early) */
00280    enum ast_bridge_result (* const early_bridge)(struct ast_channel *c0, struct ast_channel *c1);
00281 
00282    /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */
00283    int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen);
00284 
00285    /*! \brief Fix up a channel:  If a channel is consumed, this is called.  Basically update any ->owner links */
00286    int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan);
00287 
00288    /*! \brief Set a given option */
00289    int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen);
00290 
00291    /*! \brief Query a given option */
00292    int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen);
00293 
00294    /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */
00295    int (* const transfer)(struct ast_channel *chan, const char *newdest);
00296 
00297    /*! \brief Write a frame, in standard format */
00298    int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame);
00299 
00300    /*! \brief Find bridged channel */
00301    struct ast_channel *(* const bridged_channel)(struct ast_channel *chan, struct ast_channel *bridge);
00302 
00303    /*! \brief Provide additional read items for CHANNEL() dialplan function */
00304    int (* func_channel_read)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
00305 
00306    /*! \brief Provide additional write items for CHANNEL() dialplan function */
00307    int (* func_channel_write)(struct ast_channel *chan, const char *function, char *data, const char *value);
00308 };
00309 
00310 struct ast_channel_spy_list;  /*!< \todo Add explanation here */
00311 struct ast_channel_whisper_buffer;  /*!< \todo Add explanation here */
00312 
00313 /*!
00314  * The high bit of the frame count is used as a debug marker, so
00315  * increments of the counters must be done with care.
00316  * Please use c->fin = FRAMECOUNT_INC(c->fin) and the same for c->fout.
00317  */
00318 #define  DEBUGCHAN_FLAG  0x80000000
00319 
00320 /* XXX not ideal to evaluate x twice... */
00321 #define  FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )
00322 
00323 /*!
00324  * The current value of the debug flags is stored in the two
00325  * variables global_fin and global_fout (declared in main/channel.c)
00326  */
00327 extern unsigned long global_fin, global_fout;
00328 
00329 enum ast_channel_adsicpe {
00330    AST_ADSI_UNKNOWN,
00331    AST_ADSI_AVAILABLE,
00332    AST_ADSI_UNAVAILABLE,
00333    AST_ADSI_OFFHOOKONLY,
00334 };
00335 
00336 /*! 
00337  * \brief ast_channel states
00338  *
00339  * \note Bits 0-15 of state are reserved for the state (up/down) of the line
00340  *       Bits 16-32 of state are reserved for flags
00341  */
00342 enum ast_channel_state {
00343    /*! Channel is down and available */
00344    AST_STATE_DOWN,
00345    /*! Channel is down, but reserved */
00346    AST_STATE_RESERVED,
00347    /*! Channel is off hook */
00348    AST_STATE_OFFHOOK,
00349    /*! Digits (or equivalent) have been dialed */
00350    AST_STATE_DIALING,
00351    /*! Line is ringing */
00352    AST_STATE_RING,
00353    /*! Remote end is ringing */
00354    AST_STATE_RINGING,
00355    /*! Line is up */
00356    AST_STATE_UP,
00357    /*! Line is busy */
00358    AST_STATE_BUSY,
00359    /*! Digits (or equivalent) have been dialed while offhook */
00360    AST_STATE_DIALING_OFFHOOK,
00361    /*! Channel has detected an incoming call and is waiting for ring */
00362    AST_STATE_PRERING,
00363 
00364    /*! Do not transmit voice data */
00365    AST_STATE_MUTE = (1 << 16),
00366 };
00367 
00368 /*! \brief Main Channel structure associated with a channel. 
00369  * This is the side of it mostly used by the pbx and call management.
00370  *
00371  * \note XXX It is important to remember to increment .cleancount each time
00372  *       this structure is changed. XXX
00373  */
00374 struct ast_channel {
00375    /*! \brief Technology (point to channel driver) */
00376    const struct ast_channel_tech *tech;
00377 
00378    /*! \brief Private data used by the technology driver */
00379    void *tech_pvt;
00380 
00381    AST_DECLARE_STRING_FIELDS(
00382       AST_STRING_FIELD(name);       /*!< ASCII unique channel name */
00383       AST_STRING_FIELD(language);      /*!< Language requested for voice prompts */
00384       AST_STRING_FIELD(musicclass);    /*!< Default music class */
00385       AST_STRING_FIELD(accountcode);      /*!< Account code for billing */
00386       AST_STRING_FIELD(call_forward);     /*!< Where to forward to if asked to dial on this interface */
00387       AST_STRING_FIELD(uniqueid);      /*!< Unique Channel Identifier */
00388    );
00389    
00390    /*! \brief File descriptor for channel -- Drivers will poll on these file descriptors, so at least one must be non -1.  See \ref AstFileDesc */
00391    int fds[AST_MAX_FDS];   
00392 
00393    void *music_state;            /*!< Music State*/
00394    void *generatordata;          /*!< Current generator data if there is any */
00395    struct ast_generator *generator;    /*!< Current active data generator */
00396 
00397    /*! \brief Who are we bridged to, if we're bridged. Who is proxying for us,
00398      if we are proxied (i.e. chan_agent).
00399      Do not access directly, use ast_bridged_channel(chan) */
00400    struct ast_channel *_bridge;
00401    struct ast_channel *masq;        /*!< Channel that will masquerade as us */
00402    struct ast_channel *masqr;       /*!< Who we are masquerading as */
00403    int cdrflags;              /*!< Call Detail Record Flags */
00404 
00405    int _softhangup;           /*!< Whether or not we have been hung up...  Do not set this value
00406                            directly, use ast_softhangup() */
00407    time_t   whentohangup;           /*!< Non-zero, set to actual time when channel is to be hung up */
00408    pthread_t blocker;            /*!< If anyone is blocking, this is them */
00409    ast_mutex_t lock;          /*!< Lock, can be used to lock a channel for some operations - see ast_channel_lock() */
00410    const char *blockproc;           /*!< Procedure causing blocking */
00411 
00412    const char *appl;          /*!< Current application */
00413    const char *data;          /*!< Data passed to current application */
00414    int fdno;               /*!< Which fd had an event detected on */
00415    struct sched_context *sched;        /*!< Schedule context */
00416    int streamid;              /*!< For streaming playback, the schedule ID */
00417    struct ast_filestream *stream;         /*!< Stream itself. */
00418    int vstreamid;             /*!< For streaming video playback, the schedule ID */
00419    struct ast_filestream *vstream;        /*!< Video Stream itself. */
00420    int oldwriteformat;           /*!< Original writer format */
00421    
00422    int timingfd;              /*!< Timing fd */
00423    int (*timingfunc)(void *data);
00424    void *timingdata;
00425 
00426    enum ast_channel_state _state;         /*!< State of line -- Don't write directly, use ast_setstate() */
00427    int rings;              /*!< Number of rings so far */
00428    struct ast_callerid cid;         /*!< Caller ID, name, presentation etc */
00429    char dtmfq[AST_MAX_EXTENSION];         /*!< Any/all queued DTMF characters */
00430    struct ast_frame dtmff;          /*!< DTMF frame */
00431 
00432    char context[AST_MAX_CONTEXT];         /*!< Dialplan: Current extension context */
00433    char exten[AST_MAX_EXTENSION];         /*!< Dialplan: Current extension number */
00434    int priority;              /*!< Dialplan: Current extension priority */
00435    char macrocontext[AST_MAX_CONTEXT];    /*!< Macro: Current non-macro context. See app_macro.c */
00436    char macroexten[AST_MAX_EXTENSION];    /*!< Macro: Current non-macro extension. See app_macro.c */
00437    int macropriority;            /*!< Macro: Current non-macro priority. See app_macro.c */
00438    char dialcontext[AST_MAX_CONTEXT];              /*!< Dial: Extension context that we were called from */
00439 
00440    struct ast_pbx *pbx;          /*!< PBX private structure for this channel */
00441    int amaflags;              /*!< Set BEFORE PBX is started to determine AMA flags */
00442    struct ast_cdr *cdr;          /*!< Call Detail Record */
00443    enum ast_channel_adsicpe adsicpe;      /*!< Whether or not ADSI is detected on CPE */
00444 
00445    struct ind_tone_zone *zone;         /*!< Tone zone as set in indications.conf or
00446                         in the CHANNEL dialplan function */
00447 
00448    struct ast_channel_monitor *monitor;      /*!< Channel monitoring */
00449 
00450    unsigned long insmpl;            /*!< Track the read/written samples for monitor use */
00451    unsigned long outsmpl;           /*!< Track the read/written samples for monitor use */
00452 
00453    unsigned int fin;          /*!< Frames in counters. The high bit is a debug mask, so
00454                       * the counter is only in the remaining bits */
00455    unsigned int fout;            /*!< Frames out counters. The high bit is a debug mask, so
00456                       * the counter is only in the remaining bits */
00457    int hangupcause;           /*!< Why is the channel hanged up. See causes.h */
00458    struct varshead varshead;        /*!< A linked list for channel variables 
00459                         (see \ref AstChanVar ) */
00460    ast_group_t callgroup;           /*!< Call group for call pickups */
00461    ast_group_t pickupgroup;         /*!< Pickup group - which calls groups can be picked up? */
00462    unsigned int flags;           /*!< channel flags of AST_FLAG_ type */
00463    unsigned short transfercapability;     /*!< ISDN Transfer Capbility - AST_FLAG_DIGITAL is not enough */
00464    AST_LIST_HEAD_NOLOCK(, ast_frame) readq;
00465    int alertpipe[2];
00466 
00467    int nativeformats;            /*!< Kinds of data this channel can natively handle */
00468    int readformat;               /*!< Requested read format */
00469    int writeformat;           /*!< Requested write format */
00470    struct ast_trans_pvt *writetrans;      /*!< Write translation path */
00471    struct ast_trans_pvt *readtrans;    /*!< Read translation path */
00472    int rawreadformat;            /*!< Raw read format */
00473    int rawwriteformat;           /*!< Raw write format */
00474 
00475    struct ast_channel_spy_list *spies;    /*!< Chan Spy stuff */
00476    struct ast_channel_whisper_buffer *whisper;  /*!< Whisper Paging buffer */
00477    AST_LIST_ENTRY(ast_channel) chan_list;    /*!< For easy linking */
00478    
00479    struct ast_jb jb;          /*!< The jitterbuffer state  */
00480 
00481    char emulate_dtmf_digit;         /*!< Digit being emulated */
00482    unsigned int emulate_dtmf_duration; /*!< Number of ms left to emulate DTMF for */
00483    struct timeval dtmf_begin_tv;       /*!< The time that an in process digit began */
00484 
00485    /*! \brief Data stores on the channel */
00486    AST_LIST_HEAD_NOLOCK(datastores, ast_datastore) datastores;
00487 };
00488 
00489 /*! \brief ast_channel_tech Properties */
00490 enum {
00491    /*! \brief Channels have this property if they can accept input with jitter; 
00492     *         i.e. most VoIP channels */
00493    AST_CHAN_TP_WANTSJITTER = (1 << 0),
00494    /*! \brief Channels have this property if they can create jitter; 
00495     *         i.e. most VoIP channels */
00496    AST_CHAN_TP_CREATESJITTER = (1 << 1),
00497 };
00498 
00499 /*! \brief ast_channel flags */
00500 enum {
00501    /*! Queue incoming dtmf, to be released when this flag is turned off */
00502    AST_FLAG_DEFER_DTMF =    (1 << 1),
00503    /*! write should be interrupt generator */
00504    AST_FLAG_WRITE_INT =     (1 << 2),
00505    /*! a thread is blocking on this channel */
00506    AST_FLAG_BLOCKING =      (1 << 3),
00507    /*! This is a zombie channel */
00508    AST_FLAG_ZOMBIE =        (1 << 4),
00509    /*! There is an exception pending */
00510    AST_FLAG_EXCEPTION =     (1 << 5),
00511    /*! Listening to moh XXX anthm promises me this will disappear XXX */
00512    AST_FLAG_MOH =           (1 << 6),
00513    /*! This channel is spying on another channel */
00514    AST_FLAG_SPYING =        (1 << 7),
00515    /*! This channel is in a native bridge */
00516    AST_FLAG_NBRIDGE =       (1 << 8),
00517    /*! the channel is in an auto-incrementing dialplan processor,
00518     *  so when ->priority is set, it will get incremented before
00519     *  finding the next priority to run */
00520    AST_FLAG_IN_AUTOLOOP =   (1 << 9),
00521    /*! This is an outgoing call */
00522    AST_FLAG_OUTGOING =      (1 << 10),
00523    /*! This channel is being whispered on */
00524    AST_FLAG_WHISPER =       (1 << 11),
00525    /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
00526    AST_FLAG_IN_DTMF =       (1 << 12),
00527    /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is 
00528     *  currently being emulated */
00529    AST_FLAG_EMULATE_DTMF =  (1 << 13),
00530    /*! This is set to tell the channel not to generate DTMF begin frames, and
00531     *  to instead only generate END frames. */
00532    AST_FLAG_END_DTMF_ONLY = (1 << 14),
00533 };
00534 
00535 /*! \brief ast_bridge_config flags */
00536 enum {
00537    AST_FEATURE_PLAY_WARNING = (1 << 0),
00538    AST_FEATURE_REDIRECT =     (1 << 1),
00539    AST_FEATURE_DISCONNECT =   (1 << 2),
00540    AST_FEATURE_ATXFER =       (1 << 3),
00541    AST_FEATURE_AUTOMON =      (1 << 4),
00542    AST_FEATURE_PARKCALL =     (1 << 5),
00543 };
00544 
00545 /*! \brief bridge configuration */
00546 struct ast_bridge_config {
00547    struct ast_flags features_caller;
00548    struct ast_flags features_callee;
00549    struct timeval start_time;
00550    long feature_timer;
00551    long timelimit;
00552    long play_warning;
00553    long warning_freq;
00554    const char *warning_sound;
00555    const char *end_sound;
00556    const char *start_sound;
00557    int firstpass;
00558    unsigned int flags;
00559 };
00560 
00561 struct chanmon;
00562 
00563 struct outgoing_helper {
00564    const char *context;
00565    const char *exten;
00566    int priority;
00567    const char *cid_num;
00568    const char *cid_name;
00569    const char *account;
00570    struct ast_variable *vars;
00571    struct ast_channel *parent_channel;
00572 };
00573 
00574 enum {
00575    AST_CDR_TRANSFER =   (1 << 0),
00576    AST_CDR_FORWARD =    (1 << 1),
00577    AST_CDR_CALLWAIT =   (1 << 2),
00578    AST_CDR_CONFERENCE = (1 << 3),
00579 };
00580 
00581 enum {
00582    /*! Soft hangup by device */
00583    AST_SOFTHANGUP_DEV =       (1 << 0),
00584    /*! Soft hangup for async goto */
00585    AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
00586    AST_SOFTHANGUP_SHUTDOWN =  (1 << 2),
00587    AST_SOFTHANGUP_TIMEOUT =   (1 << 3),
00588    AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
00589    AST_SOFTHANGUP_EXPLICIT =  (1 << 5),
00590    AST_SOFTHANGUP_UNBRIDGE =  (1 << 6),
00591 };
00592 
00593 
00594 /*! \brief Channel reload reasons for manager events at load or reload of configuration */
00595 enum channelreloadreason {
00596    CHANNEL_MODULE_LOAD,
00597    CHANNEL_MODULE_RELOAD,
00598    CHANNEL_CLI_RELOAD,
00599    CHANNEL_MANAGER_RELOAD,
00600 };
00601 
00602 /*! \brief Create a channel datastore structure */
00603 struct ast_datastore *ast_channel_datastore_alloc(const struct ast_datastore_info *info, char *uid);
00604 
00605 /*! \brief Free a channel datastore structure */
00606 int ast_channel_datastore_free(struct ast_datastore *datastore);
00607 
00608 /*! \brief Add a datastore to a channel */
00609 int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore);
00610 
00611 /*! \brief Remove a datastore from a channel */
00612 int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore);
00613 
00614 /*! \brief Find a datastore on a channel */
00615 struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, char *uid);
00616 
00617 /*! \brief Change the state of a channel */
00618 int ast_setstate(struct ast_channel *chan, enum ast_channel_state);
00619 
00620 /*! \brief Create a channel structure 
00621     \return Returns NULL on failure to allocate.
00622    \note New channels are 
00623    by default set to the "default" context and
00624    extension "s"
00625  */
00626 struct ast_channel *ast_channel_alloc(int needalertpipe, int state, const char *cid_num, const char *cid_name, const char *name_fmt, ...);
00627 
00628 /*! \brief Queue an outgoing frame */
00629 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);
00630 
00631 /*! \brief Queue a hangup frame */
00632 int ast_queue_hangup(struct ast_channel *chan);
00633 
00634 /*!
00635   \brief Queue a control frame with payload
00636   \param chan channel to queue frame onto
00637   \param control type of control frame
00638   \return zero on success, non-zero on failure
00639 */
00640 int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control);
00641 
00642 /*!
00643   \brief Queue a control frame with payload
00644   \param chan channel to queue frame onto
00645   \param control type of control frame
00646   \param data pointer to payload data to be included in frame
00647   \param datalen number of bytes of payload data
00648   \return zero on success, non-zero on failure
00649 
00650   The supplied payload data is copied into the frame, so the caller's copy
00651   is not modified nor freed, and the resulting frame will retain a copy of
00652   the data even if the caller frees their local copy.
00653 
00654   \note This method should be treated as a 'network transport'; in other
00655   words, your frames may be transferred across an IAX2 channel to another
00656   system, which may be a different endianness than yours. Because of this,
00657   you should ensure that either your frames will never be expected to work
00658   across systems, or that you always put your payload data into 'network byte
00659   order' before calling this function.
00660 */
00661 int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control,
00662             const void *data, size_t datalen);
00663 
00664 /*! \brief Change channel name */
00665 void ast_change_name(struct ast_channel *chan, char *newname);
00666 
00667 /*! \brief Free a channel structure */
00668 void  ast_channel_free(struct ast_channel *);
00669 
00670 /*! \brief Requests a channel 
00671  * \param type type of channel to request
00672  * \param format requested channel format (codec)
00673  * \param data data to pass to the channel requester
00674  * \param status status
00675  * Request a channel of a given type, with data as optional information used 
00676  * by the low level module
00677  * \return Returns an ast_channel on success, NULL on failure.
00678  */
00679 struct ast_channel *ast_request(const char *type, int format, void *data, int *status);
00680 
00681 /*!
00682  * \brief Request a channel of a given type, with data as optional information used 
00683  * by the low level module and attempt to place a call on it
00684  * \param type type of channel to request
00685  * \param format requested channel format
00686  * \param data data to pass to the channel requester
00687  * \param timeout maximum amount of time to wait for an answer
00688  * \param reason why unsuccessful (if unsuccessful)
00689  * \param cidnum Caller-ID Number
00690  * \param cidname Caller-ID Name
00691  * \return Returns an ast_channel on success or no answer, NULL on failure.  Check the value of chan->_state
00692  * to know if the call was answered or not.
00693  */
00694 struct ast_channel *ast_request_and_dial(const char *type, int format, void *data, int timeout, int *reason, const char *cidnum, const char *cidname);
00695 
00696 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);
00697 
00698 /*!\brief Register a channel technology (a new channel driver)
00699  * Called by a channel module to register the kind of channels it supports.
00700  * \param tech Structure defining channel technology or "type"
00701  * \return Returns 0 on success, -1 on failure.
00702  */
00703 int ast_channel_register(const struct ast_channel_tech *tech);
00704 
00705 /*! \brief Unregister a channel technology 
00706  * \param tech Structure defining channel technology or "type" that was previously registered
00707  * \return No return value.
00708  */
00709 void ast_channel_unregister(const struct ast_channel_tech *tech);
00710 
00711 /*! \brief Get a channel technology structure by name
00712  * \param name name of technology to find
00713  * \return a pointer to the structure, or NULL if no matching technology found
00714  */
00715 const struct ast_channel_tech *ast_get_channel_tech(const char *name);
00716 
00717 /*! \brief Hang up a channel  
00718  * \note This function performs a hard hangup on a channel.  Unlike the soft-hangup, this function
00719  * performs all stream stopping, etc, on the channel that needs to end.
00720  * chan is no longer valid after this call.
00721  * \param chan channel to hang up
00722  * \return Returns 0 on success, -1 on failure.
00723  */
00724 int ast_hangup(struct ast_channel *chan);
00725 
00726 /*! \brief Softly hangup up a channel 
00727  * \param chan channel to be soft-hung-up
00728  * Call the protocol layer, but don't destroy the channel structure (use this if you are trying to
00729  * safely hangup a channel managed by another thread.
00730  * \param cause   Ast hangupcause for hangup
00731  * \return Returns 0 regardless
00732  */
00733 int ast_softhangup(struct ast_channel *chan, int cause);
00734 
00735 /*! \brief Softly hangup up a channel (no channel lock) 
00736  * \param chan channel to be soft-hung-up
00737  * \param cause   Ast hangupcause for hangup (see cause.h) */
00738 int ast_softhangup_nolock(struct ast_channel *chan, int cause);
00739 
00740 /*! \brief Check to see if a channel is needing hang up 
00741  * \param chan channel on which to check for hang up
00742  * This function determines if the channel is being requested to be hung up.
00743  * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
00744  */
00745 int ast_check_hangup(struct ast_channel *chan);
00746 
00747 /*! \brief Compare a offset with the settings of when to hang a channel up 
00748  * \param chan channel on which to check for hang up
00749  * \param offset offset in seconds from current time
00750  * \return 1, 0, or -1
00751  * This function compares a offset from current time with the absolute time 
00752  * out on a channel (when to hang up). If the absolute time out on a channel
00753  * is earlier than current time plus the offset, it returns 1, if the two
00754  * time values are equal, it return 0, otherwise, it return -1.
00755  */
00756 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset);
00757 
00758 /*! \brief Set when to hang a channel up 
00759  * \param chan channel on which to check for hang up
00760  * \param offset offset in seconds from current time of when to hang up
00761  * This function sets the absolute time out on a channel (when to hang up).
00762  */
00763 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset);
00764 
00765 /*! \brief Answer a channel
00766  * \param chan channel to answer
00767  * This function answers a channel and handles all necessary call
00768  * setup functions.
00769  * \return Returns 0 on success, non-zero on failure
00770  */
00771 int ast_answer(struct ast_channel *chan);
00772 int __ast_answer(struct ast_channel *chan, unsigned int delay);
00773 
00774 /*! \brief Make a call 
00775  * \param chan which channel to make the call on
00776  * \param addr destination of the call
00777  * \param timeout time to wait on for connect
00778  * Place a call, take no longer than timeout ms. 
00779    \return Returns -1 on failure, 0 on not enough time 
00780    (does not automatically stop ringing), and  
00781    the number of seconds the connect took otherwise.
00782    */
00783 int ast_call(struct ast_channel *chan, char *addr, int timeout);
00784 
00785 /*! \brief Indicates condition of channel 
00786  * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
00787  * \param chan channel to change the indication
00788  * \param condition which condition to indicate on the channel
00789  * \return Returns 0 on success, -1 on failure
00790  */
00791 int ast_indicate(struct ast_channel *chan, int condition);
00792 
00793 /*! \brief Indicates condition of channel, with payload
00794  * \note Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class
00795  * \param chan channel to change the indication
00796  * \param condition which condition to indicate on the channel
00797  * \param data pointer to payload data
00798  * \param datalen size of payload data
00799  * \return Returns 0 on success, -1 on failure
00800  */
00801 int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen);
00802 
00803 /* Misc stuff ------------------------------------------------ */
00804 
00805 /*! \brief Wait for input on a channel 
00806  * \param chan channel to wait on
00807  * \param ms length of time to wait on the channel
00808  * Wait for input on a channel for a given # of milliseconds (<0 for indefinite). 
00809   \return Returns < 0 on  failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */
00810 int ast_waitfor(struct ast_channel *chan, int ms);
00811 
00812 /*! \brief Wait for a specified amount of time, looking for hangups 
00813  * \param chan channel to wait for
00814  * \param ms length of time in milliseconds to sleep
00815  * Waits for a specified amount of time, servicing the channel as required.
00816  * \return returns -1 on hangup, otherwise 0.
00817  */
00818 int ast_safe_sleep(struct ast_channel *chan, int ms);
00819 
00820 /*! \brief Wait for a specified amount of time, looking for hangups and a condition argument 
00821  * \param chan channel to wait for
00822  * \param ms length of time in milliseconds to sleep
00823  * \param cond a function pointer for testing continue condition
00824  * \param data argument to be passed to the condition test function
00825  * \return returns -1 on hangup, otherwise 0.
00826  * Waits for a specified amount of time, servicing the channel as required. If cond
00827  * returns 0, this function returns.
00828  */
00829 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );
00830 
00831 /*! \brief Waits for activity on a group of channels 
00832  * \param chan an array of pointers to channels
00833  * \param n number of channels that are to be waited upon
00834  * \param fds an array of fds to wait upon
00835  * \param nfds the number of fds to wait upon
00836  * \param exception exception flag
00837  * \param outfd fd that had activity on it
00838  * \param ms how long the wait was
00839  * Big momma function here.  Wait for activity on any of the n channels, or any of the nfds
00840    file descriptors.
00841    \return Returns the channel with activity, or NULL on error or if an FD
00842    came first.  If the FD came first, it will be returned in outfd, otherwise, outfd
00843    will be -1 */
00844 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n, int *fds, int nfds, int *exception, int *outfd, int *ms);
00845 
00846 /*! \brief Waits for input on a group of channels
00847    Wait for input on an array of channels for a given # of milliseconds. 
00848    \return Return channel with activity, or NULL if none has activity.  
00849    \param chan an array of pointers to channels
00850    \param n number of channels that are to be waited upon
00851    \param ms time "ms" is modified in-place, if applicable */
00852 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
00853 
00854 /*! \brief Waits for input on an fd
00855    This version works on fd's only.  Be careful with it. */
00856 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);
00857 
00858 
00859 /*! \brief Reads a frame
00860  * \param chan channel to read a frame from
00861  * \return Returns a frame, or NULL on error.  If it returns NULL, you
00862    best just stop reading frames and assume the channel has been
00863    disconnected. */
00864 struct ast_frame *ast_read(struct ast_channel *chan);
00865 
00866 /*! \brief Reads a frame, returning AST_FRAME_NULL frame if audio. 
00867    \param chan channel to read a frame from
00868    \return  Returns a frame, or NULL on error.  If it returns NULL, you
00869       best just stop reading frames and assume the channel has been
00870       disconnected.  
00871    \note Audio is replaced with AST_FRAME_NULL to avoid 
00872    transcode when the resulting audio is not necessary. */
00873 struct ast_frame *ast_read_noaudio(struct ast_channel *chan);
00874 
00875 /*! \brief Write a frame to a channel 
00876  * This function writes the given frame to the indicated channel.
00877  * \param chan destination channel of the frame
00878  * \param frame frame that will be written
00879  * \return It returns 0 on success, -1 on failure.
00880  */
00881 int ast_write(struct ast_channel *chan, struct ast_frame *frame);
00882 
00883 /*! \brief Write video frame to a channel 
00884  * This function writes the given frame to the indicated channel.
00885  * \param chan destination channel of the frame
00886  * \param frame frame that will be written
00887  * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
00888  */
00889 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);
00890 
00891 /*! \brief Send empty audio to prime a channel driver */
00892 int ast_prod(struct ast_channel *chan);
00893 
00894 /*! \brief Sets read format on channel chan
00895  * Set read format for channel to whichever component of "format" is best. 
00896  * \param chan channel to change
00897  * \param format format to change to
00898  * \return Returns 0 on success, -1 on failure
00899  */
00900 int ast_set_read_format(struct ast_channel *chan, int format);
00901 
00902 /*! \brief Sets write format on channel chan
00903  * Set write format for channel to whichever component of "format" is best. 
00904  * \param chan channel to change
00905  * \param format new format for writing
00906  * \return Returns 0 on success, -1 on failure
00907  */
00908 int ast_set_write_format(struct ast_channel *chan, int format);
00909 
00910 /*! \brief Sends text to a channel 
00911  * Write text to a display on a channel
00912  * \param chan channel to act upon
00913  * \param text string of text to send on the channel
00914  * \return Returns 0 on success, -1 on failure
00915  */
00916 int ast_sendtext(struct ast_channel *chan, const char *text);
00917 
00918 /*! \brief Receives a text character from a channel
00919  * \param chan channel to act upon
00920  * \param timeout timeout in milliseconds (0 for infinite wait)
00921  * Read a char of text from a channel
00922  * Returns 0 on success, -1 on failure
00923  */
00924 int ast_recvchar(struct ast_channel *chan, int timeout);
00925 
00926 /*! \brief Send a DTMF digit to a channel
00927  * Send a DTMF digit to a channel.
00928  * \param chan channel to act upon
00929  * \param digit the DTMF digit to send, encoded in ASCII
00930  * \return Returns 0 on success, -1 on failure
00931  */
00932 int ast_senddigit(struct ast_channel *chan, char digit);
00933 
00934 /*! \brief Send a DTMF digit to a channel
00935  * Send a DTMF digit to a channel.
00936  * \param chan channel to act upon
00937  * \param digit the DTMF digit to send, encoded in ASCII
00938  * \return Returns 0 on success, -1 on failure
00939  */
00940 int ast_senddigit_begin(struct ast_channel *chan, char digit);
00941 
00942 /*! \brief Send a DTMF digit to a channel
00943 
00944  * Send a DTMF digit to a channel.
00945  * \param chan channel to act upon
00946  * \param digit the DTMF digit to send, encoded in ASCII
00947  * \param duration the duration of the digit ending in ms
00948  * \return Returns 0 on success, -1 on failure
00949  */
00950 int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration);
00951 
00952 /*! \brief Receives a text string from a channel
00953  * Read a string of text from a channel
00954  * \param chan channel to act upon
00955  * \param timeout timeout in milliseconds (0 for infinite wait)
00956  * \return the received text, or NULL to signify failure.
00957  */
00958 char *ast_recvtext(struct ast_channel *chan, int timeout);
00959 
00960 /*! \brief Browse channels in use
00961  * Browse the channels currently in use 
00962  * \param prev where you want to start in the channel list
00963  * \return Returns the next channel in the list, NULL on end.
00964  *    If it returns a channel, that channel *has been locked*!
00965  */
00966 struct ast_channel *ast_channel_walk_locked(const struct ast_channel *prev);
00967 
00968 /*! \brief Get channel by name (locks channel) */
00969 struct ast_channel *ast_get_channel_by_name_locked(const char *chan);
00970 
00971 /*! \brief Get channel by name prefix (locks channel) */
00972 struct ast_channel *ast_get_channel_by_name_prefix_locked(const char *name, const int namelen);
00973 
00974 /*! \brief Get channel by name prefix (locks channel) */
00975 struct ast_channel *ast_walk_channel_by_name_prefix_locked(const struct ast_channel *chan, const char *name, const int namelen);
00976 
00977 /*! \brief Get channel by exten (and optionally context) and lock it */
00978 struct ast_channel *ast_get_channel_by_exten_locked(const char *exten, const char *context);
00979 
00980 /*! \brief Get next channel by exten (and optionally context) and lock it */
00981 struct ast_channel *ast_walk_channel_by_exten_locked(const struct ast_channel *chan, const char *exten,
00982                        const char *context);
00983 
00984 /*! ! \brief Waits for a digit
00985  * \param c channel to wait for a digit on
00986  * \param ms how many milliseconds to wait
00987  * \return Returns <0 on error, 0 on no entry, and the digit on success. */
00988 int ast_waitfordigit(struct ast_channel *c, int ms);
00989 
00990 /*! \brief Wait for a digit
00991  Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading. 
00992  * \param c channel to wait for a digit on
00993  * \param ms how many milliseconds to wait
00994  * \param audiofd audio file descriptor to write to if audio frames are received
00995  * \param ctrlfd control file descriptor to monitor for reading
00996  * \return Returns 1 if ctrlfd becomes available */
00997 int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd);
00998 
00999 /*! Reads multiple digits 
01000  * \param c channel to read from
01001  * \param s string to read in to.  Must be at least the size of your length
01002  * \param len how many digits to read (maximum)
01003  * \param timeout how long to timeout between digits
01004  * \param rtimeout timeout to wait on the first digit
01005  * \param enders digits to end the string
01006  * Read in a digit string "s", max length "len", maximum timeout between 
01007    digits "timeout" (-1 for none), terminated by anything in "enders".  Give them rtimeout
01008    for the first digit.  Returns 0 on normal return, or 1 on a timeout.  In the case of
01009    a timeout, any digits that were read before the timeout will still be available in s.  
01010    RETURNS 2 in full version when ctrlfd is available, NOT 1*/
01011 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
01012 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);
01013 
01014 /*! \brief Report DTMF on channel 0 */
01015 #define AST_BRIDGE_DTMF_CHANNEL_0      (1 << 0)    
01016 /*! \brief Report DTMF on channel 1 */
01017 #define AST_BRIDGE_DTMF_CHANNEL_1      (1 << 1)    
01018 /*! \brief Return all voice frames on channel 0 */
01019 #define AST_BRIDGE_REC_CHANNEL_0    (1 << 2)    
01020 /*! \brief Return all voice frames on channel 1 */
01021 #define AST_BRIDGE_REC_CHANNEL_1    (1 << 3)    
01022 /*! \brief Ignore all signal frames except NULL */
01023 #define AST_BRIDGE_IGNORE_SIGS         (1 << 4)    
01024 
01025 
01026 /*! \brief Makes two channel formats compatible 
01027  * \param c0 first channel to make compatible
01028  * \param c1 other channel to make compatible
01029  * Set two channels to compatible formats -- call before ast_channel_bridge in general .  
01030  * \return Returns 0 on success and -1 if it could not be done */
01031 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
01032 
01033 /*! Bridge two channels together (early)
01034  * \param c0 first channel to bridge
01035  * \param c1 second channel to bridge
01036  * Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet.
01037  * \return Returns 0 on success and -1 if it could not be done */
01038 int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
01039 
01040 /*! Bridge two channels together 
01041  * \param c0 first channel to bridge
01042  * \param c1 second channel to bridge
01043  * \param config config for the channels
01044  * \param fo destination frame(?)
01045  * \param rc destination channel(?)
01046  * Bridge two channels (c0 and c1) together.  If an important frame occurs, we return that frame in
01047    *rf (remember, it could be NULL) and which channel (0 or 1) in rc */
01048 /* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */
01049 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);
01050 
01051 /*! \brief Weird function made for call transfers
01052  * \param original channel to make a copy of
01053  * \param clone copy of the original channel
01054  * This is a very strange and freaky function used primarily for transfer.  Suppose that
01055    "original" and "clone" are two channels in random situations.  This function takes
01056    the guts out of "clone" and puts them into the "original" channel, then alerts the
01057    channel driver of the change, asking it to fixup any private information (like the
01058    p->owner pointer) that is affected by the change.  The physical layer of the original
01059    channel is hung up.  */
01060 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone);
01061 
01062 /*! Gives the string form of a given cause code */
01063 /*! 
01064  * \param state cause to get the description of
01065  * Give a name to a cause code
01066  * Returns the text form of the binary cause code given
01067  */
01068 const char *ast_cause2str(int state) attribute_pure;
01069 
01070 /*! Convert the string form of a cause code to a number */
01071 /*! 
01072  * \param name string form of the cause
01073  * Returns the cause code
01074  */
01075 int ast_str2cause(const char *name) attribute_pure;
01076 
01077 /*! Gives the string form of a given channel state */
01078 /*! 
01079  * \param ast_channel_state state to get the name of
01080  * Give a name to a state 
01081  * Returns the text form of the binary state given
01082  */
01083 const char *ast_state2str(enum ast_channel_state);
01084 
01085 /*! Gives the string form of a given transfer capability */
01086 /*!
01087  * \param transfercapability transfercapabilty to get the name of
01088  * Give a name to a transfercapbility
01089  * See above
01090  * Returns the text form of the binary transfer capbaility
01091  */
01092 char *ast_transfercapability2str(int transfercapability) attribute_const;
01093 
01094 /* Options: Some low-level drivers may implement "options" allowing fine tuning of the
01095    low level channel.  See frame.h for options.  Note that many channel drivers may support
01096    none or a subset of those features, and you should not count on this if you want your
01097    asterisk application to be portable.  They're mainly useful for tweaking performance */
01098 
01099 /*! Sets an option on a channel */
01100 /*! 
01101  * \param channel channel to set options on
01102  * \param option option to change
01103  * \param data data specific to option
01104  * \param datalen length of the data
01105  * \param block blocking or not
01106  * Set an option on a channel (see frame.h), optionally blocking awaiting the reply 
01107  * Returns 0 on success and -1 on failure
01108  */
01109 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);
01110 
01111 /*! Pick the best codec  */
01112 /* Choose the best codec...  Uhhh...   Yah. */
01113 int ast_best_codec(int fmts);
01114 
01115 
01116 /*! Checks the value of an option */
01117 /*! 
01118  * Query the value of an option, optionally blocking until a reply is received
01119  * Works similarly to setoption except only reads the options.
01120  */
01121 struct ast_frame *ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);
01122 
01123 /*! Checks for HTML support on a channel */
01124 /*! Returns 0 if channel does not support HTML or non-zero if it does */
01125 int ast_channel_supports_html(struct ast_channel *channel);
01126 
01127 /*! Sends HTML on given channel */
01128 /*! Send HTML or URL on link.  Returns 0 on success or -1 on failure */
01129 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);
01130 
01131 /*! Sends a URL on a given link */
01132 /*! Send URL on link.  Returns 0 on success or -1 on failure */
01133 int ast_channel_sendurl(struct ast_channel *channel, const char *url);
01134 
01135 /*! Defers DTMF */
01136 /*! Defer DTMF so that you only read things like hangups and audio.  Returns
01137    non-zero if channel was already DTMF-deferred or 0 if channel is just now
01138    being DTMF-deferred */
01139 int ast_channel_defer_dtmf(struct ast_channel *chan);
01140 
01141 /*! Undo defer.  ast_read will return any dtmf characters that were queued */
01142 void ast_channel_undefer_dtmf(struct ast_channel *chan);
01143 
01144 /*! Initiate system shutdown -- prevents new channels from being allocated.
01145     If "hangup" is non-zero, all existing channels will receive soft
01146      hangups */
01147 void ast_begin_shutdown(int hangup);
01148 
01149 /*! Cancels an existing shutdown and returns to normal operation */
01150 void ast_cancel_shutdown(void);
01151 
01152 /*! Returns number of active/allocated channels */
01153 int ast_active_channels(void);
01154 
01155 /*! Returns non-zero if Asterisk is being shut down */
01156 int ast_shutting_down(void);
01157 
01158 /*! Activate a given generator */
01159 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);
01160 
01161 /*! Deactivate an active generator */
01162 void ast_deactivate_generator(struct ast_channel *chan);
01163 
01164 void ast_set_callerid(struct ast_channel *chan, const char *cidnum, const char *cidname, const char *ani);
01165 
01166 /*! Start a tone going */
01167 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
01168 /*! Stop a tone from playing */
01169 void ast_tonepair_stop(struct ast_channel *chan);
01170 /*! Play a tone pair for a given amount of time */
01171 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
01172 
01173 /*!
01174  * \brief Automatically service a channel for us... 
01175  *
01176  * \retval 0 success
01177  * \retval -1 failure, or the channel is already being autoserviced
01178  */
01179 int ast_autoservice_start(struct ast_channel *chan);
01180 
01181 /*! 
01182  * \brief Stop servicing a channel for us...  
01183  *
01184  * \retval 0 success
01185  * \retval -1 error, or the channel has been hungup 
01186  */
01187 int ast_autoservice_stop(struct ast_channel *chan);
01188 
01189 /* If built with zaptel optimizations, force a scheduled expiration on the
01190    timer fd, at which point we call the callback function / data */
01191 int ast_settimeout(struct ast_channel *c, int samples, int (*func)(void *data), void *data);
01192 
01193 /*!   \brief Transfer a channel (if supported).  Returns -1 on error, 0 if not supported
01194    and 1 if supported and requested 
01195    \param chan current channel
01196    \param dest destination extension for transfer
01197 */
01198 int ast_transfer(struct ast_channel *chan, char *dest);
01199 
01200 /*!   \brief  Start masquerading a channel
01201    XXX This is a seriously whacked out operation.  We're essentially putting the guts of
01202            the clone channel into the original channel.  Start by killing off the original
01203            channel's backend.   I'm not sure we're going to keep this function, because
01204            while the features are nice, the cost is very high in terms of pure nastiness. XXX
01205    \param chan    Channel to masquerade
01206 */
01207 int ast_do_masquerade(struct ast_channel *chan);
01208 
01209 /*!   \brief Find bridged channel 
01210    \param chan Current channel
01211 */
01212 struct ast_channel *ast_bridged_channel(struct ast_channel *chan);
01213 
01214 /*!
01215   \brief Inherits channel variable from parent to child channel
01216   \param parent Parent channel
01217   \param child Child channel
01218 
01219   Scans all channel variables in the parent channel, looking for those
01220   that should be copied into the child channel.
01221   Variables whose names begin with a single '_' are copied into the
01222   child channel with the prefix removed.
01223   Variables whose names begin with '__' are copied into the child
01224   channel with their names unchanged.
01225 */
01226 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);
01227 
01228 /*!
01229   \brief adds a list of channel variables to a channel
01230   \param chan the channel
01231   \param vars a linked list of variables
01232 
01233   Variable names can be for a regular channel variable or a dialplan function
01234   that has the ability to be written to.
01235 */
01236 void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);
01237 
01238 /*!
01239   \brief An opaque 'object' structure use by silence generators on channels.
01240  */
01241 struct ast_silence_generator;
01242 
01243 /*!
01244   \brief Starts a silence generator on the given channel.
01245   \param chan The channel to generate silence on
01246   \return An ast_silence_generator pointer, or NULL if an error occurs
01247 
01248   This function will cause SLINEAR silence to be generated on the supplied
01249   channel until it is disabled; if the channel cannot be put into SLINEAR
01250   mode then the function will fail.
01251 
01252   The pointer returned by this function must be preserved and passed to
01253   ast_channel_stop_silence_generator when you wish to stop the silence
01254   generation.
01255  */
01256 struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);
01257 
01258 /*!
01259   \brief Stops a previously-started silence generator on the given channel.
01260   \param chan The channel to operate on
01261   \param state The ast_silence_generator pointer return by a previous call to
01262   ast_channel_start_silence_generator.
01263   \return nothing
01264 
01265   This function will stop the operating silence generator and return the channel
01266   to its previous write format.
01267  */
01268 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);
01269 
01270 /*!
01271   \brief Check if the channel can run in internal timing mode.
01272   \param chan The channel to check
01273   \return boolean
01274 
01275   This function will return 1 if internal timing is enabled and the timing
01276   device is available.
01277  */
01278 int ast_internal_timing_enabled(struct ast_channel *chan);
01279 
01280 /* Misc. functions below */
01281 
01282 /*! \brief if fd is a valid descriptor, set *pfd with the descriptor
01283  * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the
01284  * return value to the index into the array)
01285  */
01286 static inline int ast_add_fd(struct pollfd *pfd, int fd)
01287 {
01288    pfd->fd = fd;
01289    pfd->events = POLLIN | POLLPRI;
01290    return fd >= 0;
01291 }
01292 
01293 /*! \brief Helper function for migrating select to poll */
01294 static inline int ast_fdisset(struct pollfd *pfds, int fd, int max, int *start)
01295 {
01296    int x;
01297    int dummy=0;
01298 
01299    if (fd < 0)
01300       return 0;
01301    if (!start)
01302       start = &dummy;
01303    for (x = *start; x<max; x++)
01304       if (pfds[x].fd == fd) {
01305          if (x == *start)
01306             (*start)++;
01307          return pfds[x].revents;
01308       }
01309    return 0;
01310 }
01311 
01312 #ifdef SOLARIS
01313 static inline void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff)
01314 {
01315    tvdiff->tv_sec = tvend->tv_sec - tvstart->tv_sec;
01316    tvdiff->tv_usec = tvend->tv_usec - tvstart->tv_usec;
01317    if (tvdiff->tv_usec < 0) {
01318       tvdiff->tv_sec --;
01319       tvdiff->tv_usec += 1000000;
01320    }
01321 
01322 }
01323 #endif
01324 
01325 /*! \brief Waits for activity on a group of channels 
01326  * \param nfds the maximum number of file descriptors in the sets
01327  * \param rfds file descriptors to check for read availability
01328  * \param wfds file descriptors to check for write availability
01329  * \param efds file descriptors to check for exceptions (OOB data)
01330  * \param tvp timeout while waiting for events
01331  * This is the same as a standard select(), except it guarantees the
01332  * behaviour where the passed struct timeval is updated with how much
01333  * time was not slept while waiting for the specified events
01334  */
01335 static inline int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp)
01336 {
01337 #ifdef __linux__
01338    return select(nfds, rfds, wfds, efds, tvp);
01339 #else
01340    if (tvp) {
01341       struct timeval tv, tvstart, tvend, tvlen;
01342       int res;
01343 
01344       tv = *tvp;
01345       gettimeofday(&tvstart, NULL);
01346       res = select(nfds, rfds, wfds, efds, tvp);
01347       gettimeofday(&tvend, NULL);
01348       timersub(&tvend, &tvstart, &tvlen);
01349       timersub(&tv, &tvlen, tvp);
01350       if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) {
01351          tvp->tv_sec = 0;
01352          tvp->tv_usec = 0;
01353       }
01354       return res;
01355    }
01356    else
01357       return select(nfds, rfds, wfds, efds, NULL);
01358 #endif
01359 }
01360 
01361 #ifdef DO_CRASH
01362 #define CRASH do { fprintf(stderr, "!! Forcing immediate crash a-la abort !!\n"); *((int *)0) = 0; } while(0)
01363 #else
01364 #define CRASH do { } while(0)
01365 #endif
01366 
01367 #define CHECK_BLOCKING(c) {    \
01368                      if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\
01369                         ast_log(LOG_WARNING, "Thread %ld Blocking '%s', already blocked by thread %ld in procedure %s\n", (long) pthread_self(), (c)->name, (long) (c)->blocker, (c)->blockproc); \
01370                         CRASH; \
01371                      } else { \
01372                         (c)->blocker = pthread_self(); \
01373                         (c)->blockproc = __PRETTY_FUNCTION__; \
01374                            ast_set_flag(c, AST_FLAG_BLOCKING); \
01375                            } }
01376 
01377 ast_group_t ast_get_group(const char *s);
01378 
01379 /*! \brief print call- and pickup groups into buffer */
01380 char *ast_print_group(char *buf, int buflen, ast_group_t group);
01381 
01382 /*! \brief Convert enum channelreloadreason to text string for manager event
01383    \param reason  Enum channelreloadreason - reason for reload (manager, cli, start etc)
01384 */
01385 const char *channelreloadreason2txt(enum channelreloadreason reason);
01386 
01387 /*! \brief return an ast_variable list of channeltypes */
01388 struct ast_variable *ast_channeltype_list(void);
01389 
01390 /*!
01391   \brief Begin 'whispering' onto a channel
01392   \param chan The channel to whisper onto
01393   \return 0 for success, non-zero for failure
01394 
01395   This function will add a whisper buffer onto a channel and set a flag
01396   causing writes to the channel to reduce the volume level of the written
01397   audio samples, and then to mix in audio from the whisper buffer if it
01398   is available.
01399 
01400   \note Note: This function performs no locking; you must hold the channel's lock before
01401   calling this function.
01402  */
01403 int ast_channel_whisper_start(struct ast_channel *chan);
01404 
01405 /*!
01406   \brief Feed an audio frame into the whisper buffer on a channel
01407   \param chan The channel to whisper onto
01408   \param f The frame to to whisper onto chan
01409   \return 0 for success, non-zero for failure
01410  */
01411 int ast_channel_whisper_feed(struct ast_channel *chan, struct ast_frame *f);
01412 
01413 /*!
01414   \brief Stop 'whispering' onto a channel
01415   \param chan The channel to whisper onto
01416   \return 0 for success, non-zero for failure
01417 
01418   Note: This function performs no locking; you must hold the channel's lock before
01419   calling this function.
01420  */
01421 void ast_channel_whisper_stop(struct ast_channel *chan);
01422 
01423 #if defined(__cplusplus) || defined(c_plusplus)
01424 }
01425 #endif
01426 
01427 #endif /* _ASTERISK_CHANNEL_H */

Asterisk is a trademark for Digium, inc.. | Edvina.net | Asterisk.org | This documentation was generated with Doxygen