2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2006, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
20 * \brief General Asterisk PBX channel definitions.
22 * \arg \ref Def_Channel
23 * \arg \ref channel_drivers
26 /*! \page Def_Channel Asterisk Channels
27 \par What is a Channel?
28 A phone call through Asterisk consists of an incoming
29 connection and an outbound connection. Each call comes
30 in through a channel driver that supports one technology,
31 like SIP, ZAP, IAX2 etc.
33 Each channel driver, technology, has it's own private
34 channel or dialog structure, that is technology-dependent.
35 Each private structure is "owned" by a generic Asterisk
36 channel structure, defined in channel.h and handled by
39 This happens when an incoming call arrives to Asterisk
40 -# Call arrives on a channel driver interface
41 -# Channel driver creates a PBX channel and starts a
42 pbx thread on the channel
43 -# The dial plan is executed
44 -# At this point at least two things can happen:
45 -# The call is answered by Asterisk and
46 Asterisk plays a media stream or reads media
47 -# The dial plan forces Asterisk to create an outbound
48 call somewhere with the dial (see \ref app_dial.c)
52 \par Bridging channels
53 If Asterisk dials out this happens:
54 -# Dial creates an outbound PBX channel and asks one of the
55 channel drivers to create a call
56 -# When the call is answered, Asterisk bridges the media streams
57 so the caller on the first channel can speak with the callee
58 on the second, outbound channel
59 -# In some cases where we have the same technology on both
60 channels and compatible codecs, a native bridge is used.
61 In a native bridge, the channel driver handles forwarding
62 of incoming audio to the outbound stream internally, without
63 sending audio frames through the PBX.
64 -# In SIP, theres an "external native bridge" where Asterisk
65 redirects the endpoint, so audio flows directly between the
66 caller's phone and the callee's phone. Signalling stays in
67 Asterisk in order to be able to provide a proper CDR record
71 \par Masquerading channels
72 In some cases, a channel can masquerade itself into another
73 channel. This happens frequently in call transfers, where
74 a new channel takes over a channel that is already involved
75 in a call. The new channel sneaks in and takes over the bridge
76 and the old channel, now a zombie, is hung up.
79 \arg channel.c - generic functions
80 \arg channel.h - declarations of functions, flags and structures
81 \arg translate.h - Transcoding support functions
82 \arg \ref channel_drivers - Implemented channel drivers
83 \arg \ref Def_Frame Asterisk Multimedia Frames
87 /*! \page Def_Bridge Asterisk Channel Bridges
89 In Asterisk, there's several media bridges.
91 The Core bridge handles two channels (a "phone call") and bridge
94 The conference bridge (meetme) handles several channels simultaneously
95 with the support of an external timer (zaptel timer). This is used
96 not only by the Conference application (meetme) but also by the
97 page application and the SLA system introduced in 1.4.
98 The conference bridge does not handle video.
100 When two channels of the same type connect, the channel driver
101 or the media subsystem used by the channel driver (i.e. RTP)
102 can create a native bridge without sending media through the
105 Native briding can be disabled by a number of reasons,
106 like DTMF being needed by the core or codecs being incompatible
107 so a transcoding module is needed.
110 \li \see ast_channel_early_bridge()
111 \li \see ast_channel_bridge()
112 \li \see app_meetme.c
113 \li \ref AstRTPbridge
114 \li \see ast_rtp_bridge()
118 /*! \page AstFileDesc File descriptors
119 Asterisk File descriptors are connected to each channel (see \ref Def_Channel)
120 in the \ref ast_channel structure.
123 #ifndef _ASTERISK_CHANNEL_H
124 #define _ASTERISK_CHANNEL_H
126 #include "asterisk/abstract_jb.h"
130 #include "asterisk/poll-compat.h"
132 #include <sys/poll.h>
135 #if defined(__cplusplus) || defined(c_plusplus)
139 #define AST_MAX_EXTENSION 80 /*!< Max length of an extension */
140 #define AST_MAX_CONTEXT 80 /*!< Max length of a context */
141 #define AST_CHANNEL_NAME 80 /*!< Max length of an ast_channel name */
142 #define MAX_LANGUAGE 20 /*!< Max length of the language setting */
143 #define MAX_MUSICCLASS 80 /*!< Max length of the music class setting */
145 #include "asterisk/compat.h"
146 #include "asterisk/frame.h"
147 #include "asterisk/sched.h"
148 #include "asterisk/chanvars.h"
149 #include "asterisk/config.h"
150 #include "asterisk/lock.h"
151 #include "asterisk/cdr.h"
152 #include "asterisk/utils.h"
153 #include "asterisk/linkedlists.h"
154 #include "asterisk/stringfields.h"
155 #include "asterisk/compiler.h"
158 #define DATASTORE_INHERIT_FOREVER INT_MAX
160 #define AST_MAX_FDS 10
162 * We have AST_MAX_FDS file descriptors in a channel.
163 * Some of them have a fixed use:
165 #define AST_ALERT_FD (AST_MAX_FDS-1) /*!< used for alertpipe */
166 #define AST_TIMING_FD (AST_MAX_FDS-2) /*!< used for timingfd */
167 #define AST_AGENT_FD (AST_MAX_FDS-3) /*!< used by agents for pass through */
168 #define AST_GENERATOR_FD (AST_MAX_FDS-4) /*!< used by generator */
170 enum ast_bridge_result {
171 AST_BRIDGE_COMPLETE = 0,
172 AST_BRIDGE_FAILED = -1,
173 AST_BRIDGE_FAILED_NOWARN = -2,
174 AST_BRIDGE_RETRY = -3,
177 typedef unsigned long long ast_group_t;
179 /*! \todo Add an explanation of an Asterisk generator
181 struct ast_generator {
182 void *(*alloc)(struct ast_channel *chan, void *params);
183 void (*release)(struct ast_channel *chan, void *data);
184 int (*generate)(struct ast_channel *chan, void *data, int len, int samples);
185 /*! This gets called when DTMF_END frames are read from the channel */
186 void (*digit)(struct ast_channel *chan, char digit);
189 /*! \brief Structure for a data store type */
190 struct ast_datastore_info {
191 const char *type; /*!< Type of data store */
192 void *(*duplicate)(void *data); /*!< Duplicate item data (used for inheritance) */
193 void (*destroy)(void *data); /*!< Destroy function */
196 /*! \brief Structure for a channel data store */
197 struct ast_datastore {
198 char *uid; /*!< Unique data store identifier */
199 void *data; /*!< Contained data */
200 const struct ast_datastore_info *info; /*!< Data store type information */
201 unsigned int inheritance; /*!< Number of levels this item will continue to be inherited */
202 AST_LIST_ENTRY(ast_datastore) entry; /*!< Used for easy linking */
205 /*! \brief Structure for all kinds of caller ID identifications.
206 * \note All string fields here are malloc'ed, so they need to be
207 * freed when the structure is deleted.
208 * Also, NULL and "" must be considered equivalent.
210 struct ast_callerid {
211 char *cid_dnid; /*!< Malloc'd Dialed Number Identifier */
212 char *cid_num; /*!< Malloc'd Caller Number */
213 char *cid_name; /*!< Malloc'd Caller Name */
214 char *cid_ani; /*!< Malloc'd ANI */
215 char *cid_rdnis; /*!< Malloc'd RDNIS */
216 int cid_pres; /*!< Callerid presentation/screening */
217 int cid_ani2; /*!< Callerid ANI 2 (Info digits) */
218 int cid_ton; /*!< Callerid Type of Number */
219 int cid_tns; /*!< Callerid Transit Network Select */
223 Structure to describe a channel "technology", ie a channel driver
225 \arg chan_iax2.c - The Inter-Asterisk exchange protocol
226 \arg chan_sip.c - The SIP channel driver
227 \arg chan_zap.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS)
229 If you develop your own channel driver, this is where you
230 tell the PBX at registration of your driver what properties
231 this driver supports and where different callbacks are
234 struct ast_channel_tech {
235 const char * const type;
236 const char * const description;
238 int capabilities; /*!< Bitmap of formats this channel can handle */
240 int properties; /*!< Technology Properties */
242 /*! \brief Requester - to set up call data structures (pvt's) */
243 struct ast_channel *(* const requester)(const char *type, int format, void *data, int *cause);
245 int (* const devicestate)(void *data); /*!< Devicestate call back */
247 /*! \brief Start sending a literal DTMF digit */
248 int (* const send_digit_begin)(struct ast_channel *chan, char digit);
250 /*! \brief Stop sending a literal DTMF digit */
251 int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration);
253 /*! \brief Call a given phone number (address, etc), but don't
254 take longer than timeout seconds to do so. */
255 int (* const call)(struct ast_channel *chan, char *addr, int timeout);
257 /*! \brief Hangup (and possibly destroy) the channel */
258 int (* const hangup)(struct ast_channel *chan);
260 /*! \brief Answer the channel */
261 int (* const answer)(struct ast_channel *chan);
263 /*! \brief Read a frame, in standard format (see frame.h) */
264 struct ast_frame * (* const read)(struct ast_channel *chan);
266 /*! \brief Write a frame, in standard format (see frame.h) */
267 int (* const write)(struct ast_channel *chan, struct ast_frame *frame);
269 /*! \brief Display or transmit text */
270 int (* const send_text)(struct ast_channel *chan, const char *text);
272 /*! \brief Display or send an image */
273 int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame);
275 /*! \brief Send HTML data */
276 int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len);
278 /*! \brief Handle an exception, reading a frame */
279 struct ast_frame * (* const exception)(struct ast_channel *chan);
281 /*! \brief Bridge two channels of the same type together */
282 enum ast_bridge_result (* const bridge)(struct ast_channel *c0, struct ast_channel *c1, int flags,
283 struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
285 /*! \brief Bridge two channels of the same type together (early) */
286 enum ast_bridge_result (* const early_bridge)(struct ast_channel *c0, struct ast_channel *c1);
288 /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */
289 int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen);
291 /*! \brief Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links */
292 int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan);
294 /*! \brief Set a given option */
295 int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen);
297 /*! \brief Query a given option */
298 int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen);
300 /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */
301 int (* const transfer)(struct ast_channel *chan, const char *newdest);
303 /*! \brief Write a frame, in standard format */
304 int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame);
306 /*! \brief Write a text frame, in standard format */
307 int (* const write_text)(struct ast_channel *chan, struct ast_frame *frame);
309 /*! \brief Find bridged channel */
310 struct ast_channel *(* const bridged_channel)(struct ast_channel *chan, struct ast_channel *bridge);
312 /*! \brief Provide additional read items for CHANNEL() dialplan function */
313 int (* func_channel_read)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
315 /*! \brief Provide additional write items for CHANNEL() dialplan function */
316 int (* func_channel_write)(struct ast_channel *chan, const char *function, char *data, const char *value);
319 struct ast_channel_spy_list; /*!< \todo Add explanation here */
320 struct ast_channel_whisper_buffer; /*!< \todo Add explanation here */
323 * The high bit of the frame count is used as a debug marker, so
324 * increments of the counters must be done with care.
325 * Please use c->fin = FRAMECOUNT_INC(c->fin) and the same for c->fout.
327 #define DEBUGCHAN_FLAG 0x80000000
329 /* XXX not ideal to evaluate x twice... */
330 #define FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )
333 * The current value of the debug flags is stored in the two
334 * variables global_fin and global_fout (declared in main/channel.c)
336 extern unsigned long global_fin, global_fout;
338 enum ast_channel_adsicpe {
341 AST_ADSI_UNAVAILABLE,
342 AST_ADSI_OFFHOOKONLY,
346 * \brief ast_channel states
348 * \note Bits 0-15 of state are reserved for the state (up/down) of the line
349 * Bits 16-32 of state are reserved for flags
351 enum ast_channel_state {
352 /*! Channel is down and available */
354 /*! Channel is down, but reserved */
356 /*! Channel is off hook */
358 /*! Digits (or equivalent) have been dialed */
360 /*! Line is ringing */
362 /*! Remote end is ringing */
368 /*! Digits (or equivalent) have been dialed while offhook */
369 AST_STATE_DIALING_OFFHOOK,
370 /*! Channel has detected an incoming call and is waiting for ring */
373 /*! Do not transmit voice data */
374 AST_STATE_MUTE = (1 << 16),
377 /*! \brief Main Channel structure associated with a channel.
378 * This is the side of it mostly used by the pbx and call management.
380 * \note XXX It is important to remember to increment .cleancount each time
381 * this structure is changed. XXX
384 /*! \brief Technology (point to channel driver) */
385 const struct ast_channel_tech *tech;
387 /*! \brief Private data used by the technology driver */
390 AST_DECLARE_STRING_FIELDS(
391 AST_STRING_FIELD(name); /*!< ASCII unique channel name */
392 AST_STRING_FIELD(language); /*!< Language requested for voice prompts */
393 AST_STRING_FIELD(musicclass); /*!< Default music class */
394 AST_STRING_FIELD(accountcode); /*!< Account code for billing */
395 AST_STRING_FIELD(call_forward); /*!< Where to forward to if asked to dial on this interface */
396 AST_STRING_FIELD(uniqueid); /*!< Unique Channel Identifier */
399 /*! \brief File descriptor for channel -- Drivers will poll on these file descriptors, so at least one must be non -1. See \arg \ref AstFileDesc */
400 int fds[AST_MAX_FDS];
402 void *music_state; /*!< Music State*/
403 void *generatordata; /*!< Current generator data if there is any */
404 struct ast_generator *generator; /*!< Current active data generator */
406 /*! \brief Who are we bridged to, if we're bridged. Who is proxying for us,
407 if we are proxied (i.e. chan_agent).
408 Do not access directly, use ast_bridged_channel(chan) */
409 struct ast_channel *_bridge;
410 struct ast_channel *masq; /*!< Channel that will masquerade as us */
411 struct ast_channel *masqr; /*!< Who we are masquerading as */
412 int cdrflags; /*!< Call Detail Record Flags */
414 int _softhangup; /*!< Whether or not we have been hung up... Do not set this value
415 directly, use ast_softhangup() */
416 time_t whentohangup; /*!< Non-zero, set to actual time when channel is to be hung up */
417 pthread_t blocker; /*!< If anyone is blocking, this is them */
418 ast_mutex_t lock; /*!< Lock, can be used to lock a channel for some operations - see ast_channel_lock() */
419 const char *blockproc; /*!< Procedure causing blocking */
421 const char *appl; /*!< Current application */
422 const char *data; /*!< Data passed to current application */
423 int fdno; /*!< Which fd had an event detected on */
424 struct sched_context *sched; /*!< Schedule context */
425 int streamid; /*!< For streaming playback, the schedule ID */
426 struct ast_filestream *stream; /*!< Stream itself. */
427 int vstreamid; /*!< For streaming video playback, the schedule ID */
428 struct ast_filestream *vstream; /*!< Video Stream itself. */
429 int oldwriteformat; /*!< Original writer format */
431 int timingfd; /*!< Timing fd */
432 int (*timingfunc)(void *data);
435 enum ast_channel_state _state; /*!< State of line -- Don't write directly, use ast_setstate() */
436 int rings; /*!< Number of rings so far */
437 struct ast_callerid cid; /*!< Caller ID, name, presentation etc */
438 char dtmfq[AST_MAX_EXTENSION]; /*!< Any/all queued DTMF characters */
439 struct ast_frame dtmff; /*!< DTMF frame */
441 char context[AST_MAX_CONTEXT]; /*!< Dialplan: Current extension context */
442 char exten[AST_MAX_EXTENSION]; /*!< Dialplan: Current extension number */
443 int priority; /*!< Dialplan: Current extension priority */
444 char macrocontext[AST_MAX_CONTEXT]; /*!< Macro: Current non-macro context. See app_macro.c */
445 char macroexten[AST_MAX_EXTENSION]; /*!< Macro: Current non-macro extension. See app_macro.c */
446 int macropriority; /*!< Macro: Current non-macro priority. See app_macro.c */
447 char dialcontext[AST_MAX_CONTEXT]; /*!< Dial: Extension context that we were called from */
449 struct ast_pbx *pbx; /*!< PBX private structure for this channel */
450 int amaflags; /*!< Set BEFORE PBX is started to determine AMA flags */
451 struct ast_cdr *cdr; /*!< Call Detail Record */
452 enum ast_channel_adsicpe adsicpe; /*!< Whether or not ADSI is detected on CPE */
454 struct ind_tone_zone *zone; /*!< Tone zone as set in indications.conf or
455 in the CHANNEL dialplan function */
457 struct ast_channel_monitor *monitor; /*!< Channel monitoring */
459 unsigned long insmpl; /*!< Track the read/written samples for monitor use */
460 unsigned long outsmpl; /*!< Track the read/written samples for monitor use */
462 unsigned int fin; /*!< Frames in counters. The high bit is a debug mask, so
463 * the counter is only in the remaining bits */
464 unsigned int fout; /*!< Frames out counters. The high bit is a debug mask, so
465 * the counter is only in the remaining bits */
466 int hangupcause; /*!< Why is the channel hanged up. See causes.h */
467 struct varshead varshead; /*!< A linked list for channel variables
468 (see \ref AstChanVar ) */
469 ast_group_t callgroup; /*!< Call group for call pickups */
470 ast_group_t pickupgroup; /*!< Pickup group - which calls groups can be picked up? */
471 uint64_t flags; /*!< channel flags of AST_FLAG_ type */
472 unsigned short transfercapability; /*!< ISDN Transfer Capbility - AST_FLAG_DIGITAL is not enough */
473 AST_LIST_HEAD_NOLOCK(, ast_frame) readq;
476 int nativeformats; /*!< Kinds of data this channel can natively handle */
477 int readformat; /*!< Requested read format */
478 int writeformat; /*!< Requested write format */
479 struct ast_trans_pvt *writetrans; /*!< Write translation path */
480 struct ast_trans_pvt *readtrans; /*!< Read translation path */
481 int rawreadformat; /*!< Raw read format */
482 int rawwriteformat; /*!< Raw write format */
484 struct ast_channel_spy_list *spies; /*!< Chan Spy stuff */
485 struct ast_channel_whisper_buffer *whisper; /*!< Whisper Paging buffer */
486 AST_LIST_ENTRY(ast_channel) chan_list; /*!< For easy linking */
488 struct ast_jb jb; /*!< The jitterbuffer state */
490 char emulate_dtmf_digit; /*!< Digit being emulated */
491 unsigned int emulate_dtmf_duration; /*!< Number of ms left to emulate DTMF for */
492 struct timeval dtmf_tv; /*!< The time that an in process digit began, or the last digit ended */
494 /*! \brief Data stores on the channel */
495 AST_LIST_HEAD_NOLOCK(datastores, ast_datastore) datastores;
498 /*! \brief ast_channel_tech Properties */
500 /*! \brief Channels have this property if they can accept input with jitter;
501 * i.e. most VoIP channels */
502 AST_CHAN_TP_WANTSJITTER = (1 << 0),
503 /*! \brief Channels have this property if they can create jitter;
504 * i.e. most VoIP channels */
505 AST_CHAN_TP_CREATESJITTER = (1 << 1),
508 /*! \brief ast_channel flags */
510 /*! Queue incoming dtmf, to be released when this flag is turned off */
511 AST_FLAG_DEFER_DTMF = (1 << 1),
512 /*! write should be interrupt generator */
513 AST_FLAG_WRITE_INT = (1 << 2),
514 /*! a thread is blocking on this channel */
515 AST_FLAG_BLOCKING = (1 << 3),
516 /*! This is a zombie channel */
517 AST_FLAG_ZOMBIE = (1 << 4),
518 /*! There is an exception pending */
519 AST_FLAG_EXCEPTION = (1 << 5),
520 /*! Listening to moh XXX anthm promises me this will disappear XXX */
521 AST_FLAG_MOH = (1 << 6),
522 /*! This channel is spying on another channel */
523 AST_FLAG_SPYING = (1 << 7),
524 /*! This channel is in a native bridge */
525 AST_FLAG_NBRIDGE = (1 << 8),
526 /*! the channel is in an auto-incrementing dialplan processor,
527 * so when ->priority is set, it will get incremented before
528 * finding the next priority to run */
529 AST_FLAG_IN_AUTOLOOP = (1 << 9),
530 /*! This is an outgoing call */
531 AST_FLAG_OUTGOING = (1 << 10),
532 /*! This channel is being whispered on */
533 AST_FLAG_WHISPER = (1 << 11),
534 /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
535 AST_FLAG_IN_DTMF = (1 << 12),
536 /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is
537 * currently being emulated */
538 AST_FLAG_EMULATE_DTMF = (1 << 13),
539 /*! This is set to tell the channel not to generate DTMF begin frames, and
540 * to instead only generate END frames. */
541 AST_FLAG_END_DTMF_ONLY = (1 << 14),
542 /*! Flag to show channels that this call is hangup due to the fact that the call
543 was indeed anwered, but in another channel */
544 AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15),
547 /*! \brief ast_bridge_config flags */
549 AST_FEATURE_PLAY_WARNING = (1 << 0),
550 AST_FEATURE_REDIRECT = (1 << 1),
551 AST_FEATURE_DISCONNECT = (1 << 2),
552 AST_FEATURE_ATXFER = (1 << 3),
553 AST_FEATURE_AUTOMON = (1 << 4),
554 AST_FEATURE_PARKCALL = (1 << 5),
557 /*! \brief bridge configuration */
558 struct ast_bridge_config {
559 struct ast_flags features_caller;
560 struct ast_flags features_callee;
561 struct timeval start_time;
566 const char *warning_sound;
567 const char *end_sound;
568 const char *start_sound;
575 struct outgoing_helper {
580 const char *cid_name;
582 struct ast_variable *vars;
583 struct ast_channel *parent_channel;
587 AST_CDR_TRANSFER = (1 << 0),
588 AST_CDR_FORWARD = (1 << 1),
589 AST_CDR_CALLWAIT = (1 << 2),
590 AST_CDR_CONFERENCE = (1 << 3),
594 /*! Soft hangup by device */
595 AST_SOFTHANGUP_DEV = (1 << 0),
596 /*! Soft hangup for async goto */
597 AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
598 AST_SOFTHANGUP_SHUTDOWN = (1 << 2),
599 AST_SOFTHANGUP_TIMEOUT = (1 << 3),
600 AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
601 AST_SOFTHANGUP_EXPLICIT = (1 << 5),
602 AST_SOFTHANGUP_UNBRIDGE = (1 << 6),
606 /*! \brief Channel reload reasons for manager events at load or reload of configuration */
607 enum channelreloadreason {
609 CHANNEL_MODULE_RELOAD,
611 CHANNEL_MANAGER_RELOAD,
614 /*! \brief Create a channel datastore structure */
615 struct ast_datastore *ast_channel_datastore_alloc(const struct ast_datastore_info *info, char *uid);
617 /*! \brief Free a channel datastore structure */
618 int ast_channel_datastore_free(struct ast_datastore *datastore);
620 /*! \brief Inherit datastores from a parent to a child. */
621 int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to);
623 /*! \brief Add a datastore to a channel */
624 int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore);
626 /*! \brief Remove a datastore from a channel */
627 int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore);
629 /*! \brief Find a datastore on a channel */
630 struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, char *uid);
632 /*! \brief Change the state of a channel */
633 int ast_setstate(struct ast_channel *chan, enum ast_channel_state);
635 /*! \brief Create a channel structure
636 \return Returns NULL on failure to allocate.
637 \note New channels are
638 by default set to the "default" context and
641 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, ...);
643 /*! \brief Queue an outgoing frame */
644 int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);
646 /*! \brief Queue a hangup frame */
647 int ast_queue_hangup(struct ast_channel *chan);
650 \brief Queue a control frame with payload
651 \param chan channel to queue frame onto
652 \param control type of control frame
653 \return zero on success, non-zero on failure
655 int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control);
658 \brief Queue a control frame with payload
659 \param chan channel to queue frame onto
660 \param control type of control frame
661 \param data pointer to payload data to be included in frame
662 \param datalen number of bytes of payload data
663 \return zero on success, non-zero on failure
665 The supplied payload data is copied into the frame, so the caller's copy
666 is not modified nor freed, and the resulting frame will retain a copy of
667 the data even if the caller frees their local copy.
669 \note This method should be treated as a 'network transport'; in other
670 words, your frames may be transferred across an IAX2 channel to another
671 system, which may be a different endianness than yours. Because of this,
672 you should ensure that either your frames will never be expected to work
673 across systems, or that you always put your payload data into 'network byte
674 order' before calling this function.
676 int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control,
677 const void *data, size_t datalen);
679 /*! \brief Change channel name */
680 void ast_change_name(struct ast_channel *chan, char *newname);
682 /*! \brief Free a channel structure */
683 void ast_channel_free(struct ast_channel *);
685 /*! \brief Requests a channel
686 * \param type type of channel to request
687 * \param format requested channel format (codec)
688 * \param data data to pass to the channel requester
689 * \param status status
690 * Request a channel of a given type, with data as optional information used
691 * by the low level module
692 * \return Returns an ast_channel on success, NULL on failure.
694 struct ast_channel *ast_request(const char *type, int format, void *data, int *status);
697 * \brief Request a channel of a given type, with data as optional information used
698 * by the low level module and attempt to place a call on it
699 * \param type type of channel to request
700 * \param format requested channel format
701 * \param data data to pass to the channel requester
702 * \param timeout maximum amount of time to wait for an answer
703 * \param reason why unsuccessful (if unsuccessful)
704 * \param cidnum Caller-ID Number
705 * \param cidname Caller-ID Name
706 * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state
707 * to know if the call was answered or not.
709 struct ast_channel *ast_request_and_dial(const char *type, int format, void *data, int timeout, int *reason, const char *cidnum, const char *cidname);
711 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);
713 /*!\brief Register a channel technology (a new channel driver)
714 * Called by a channel module to register the kind of channels it supports.
715 * \param tech Structure defining channel technology or "type"
716 * \return Returns 0 on success, -1 on failure.
718 int ast_channel_register(const struct ast_channel_tech *tech);
720 /*! \brief Unregister a channel technology
721 * \param tech Structure defining channel technology or "type" that was previously registered
722 * \return No return value.
724 void ast_channel_unregister(const struct ast_channel_tech *tech);
726 /*! \brief Get a channel technology structure by name
727 * \param name name of technology to find
728 * \return a pointer to the structure, or NULL if no matching technology found
730 const struct ast_channel_tech *ast_get_channel_tech(const char *name);
732 /*! \brief Hang up a channel
733 * \note This function performs a hard hangup on a channel. Unlike the soft-hangup, this function
734 * performs all stream stopping, etc, on the channel that needs to end.
735 * chan is no longer valid after this call.
736 * \param chan channel to hang up
737 * \return Returns 0 on success, -1 on failure.
739 int ast_hangup(struct ast_channel *chan);
741 /*! \brief Softly hangup up a channel
742 * \param chan channel to be soft-hung-up
743 * Call the protocol layer, but don't destroy the channel structure (use this if you are trying to
744 * safely hangup a channel managed by another thread.
745 * \param cause Ast hangupcause for hangup
746 * \return Returns 0 regardless
748 int ast_softhangup(struct ast_channel *chan, int cause);
750 /*! \brief Softly hangup up a channel (no channel lock)
751 * \param chan channel to be soft-hung-up
752 * \param cause Ast hangupcause for hangup (see cause.h) */
753 int ast_softhangup_nolock(struct ast_channel *chan, int cause);
755 /*! \brief Check to see if a channel is needing hang up
756 * \param chan channel on which to check for hang up
757 * This function determines if the channel is being requested to be hung up.
758 * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
760 int ast_check_hangup(struct ast_channel *chan);
762 /*! \brief Compare a offset with the settings of when to hang a channel up
763 * \param chan channel on which to check for hang up
764 * \param offset offset in seconds from current time
765 * \return 1, 0, or -1
766 * This function compares a offset from current time with the absolute time
767 * out on a channel (when to hang up). If the absolute time out on a channel
768 * is earlier than current time plus the offset, it returns 1, if the two
769 * time values are equal, it return 0, otherwise, it return -1.
771 int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset);
773 /*! \brief Set when to hang a channel up
774 * \param chan channel on which to check for hang up
775 * \param offset offset in seconds from current time of when to hang up
776 * This function sets the absolute time out on a channel (when to hang up).
778 void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset);
780 /*! \brief Answer a channel
781 * \param chan channel to answer
782 * This function answers a channel and handles all necessary call
784 * \return Returns 0 on success, non-zero on failure
786 int ast_answer(struct ast_channel *chan);
787 int __ast_answer(struct ast_channel *chan, unsigned int delay);
789 /*! \brief Make a call
790 * \param chan which channel to make the call on
791 * \param addr destination of the call
792 * \param timeout time to wait on for connect
793 * Place a call, take no longer than timeout ms.
794 \return Returns -1 on failure, 0 on not enough time
795 (does not automatically stop ringing), and
796 the number of seconds the connect took otherwise.
798 int ast_call(struct ast_channel *chan, char *addr, int timeout);
800 /*! \brief Indicates condition of channel
801 * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
802 * \param chan channel to change the indication
803 * \param condition which condition to indicate on the channel
804 * \return Returns 0 on success, -1 on failure
806 int ast_indicate(struct ast_channel *chan, int condition);
808 /*! \brief Indicates condition of channel, with payload
809 * \note Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class
810 * \param chan channel to change the indication
811 * \param condition which condition to indicate on the channel
812 * \param data pointer to payload data
813 * \param datalen size of payload data
814 * \return Returns 0 on success, -1 on failure
816 int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen);
818 /* Misc stuff ------------------------------------------------ */
820 /*! \brief Wait for input on a channel
821 * \param chan channel to wait on
822 * \param ms length of time to wait on the channel
823 * Wait for input on a channel for a given # of milliseconds (<0 for indefinite).
824 \return Returns < 0 on failure, 0 if nothing ever arrived, and the # of ms remaining otherwise */
825 int ast_waitfor(struct ast_channel *chan, int ms);
827 /*! \brief Wait for a specified amount of time, looking for hangups
828 * \param chan channel to wait for
829 * \param ms length of time in milliseconds to sleep
830 * Waits for a specified amount of time, servicing the channel as required.
831 * \return returns -1 on hangup, otherwise 0.
833 int ast_safe_sleep(struct ast_channel *chan, int ms);
835 /*! \brief Wait for a specified amount of time, looking for hangups and a condition argument
836 * \param chan channel to wait for
837 * \param ms length of time in milliseconds to sleep
838 * \param cond a function pointer for testing continue condition
839 * \param data argument to be passed to the condition test function
840 * \return returns -1 on hangup, otherwise 0.
841 * Waits for a specified amount of time, servicing the channel as required. If cond
842 * returns 0, this function returns.
844 int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );
846 /*! \brief Waits for activity on a group of channels
847 * \param chan an array of pointers to channels
848 * \param n number of channels that are to be waited upon
849 * \param fds an array of fds to wait upon
850 * \param nfds the number of fds to wait upon
851 * \param exception exception flag
852 * \param outfd fd that had activity on it
853 * \param ms how long the wait was
854 * Big momma function here. Wait for activity on any of the n channels, or any of the nfds
856 \return Returns the channel with activity, or NULL on error or if an FD
857 came first. If the FD came first, it will be returned in outfd, otherwise, outfd
859 struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n, int *fds, int nfds, int *exception, int *outfd, int *ms);
861 /*! \brief Waits for input on a group of channels
862 Wait for input on an array of channels for a given # of milliseconds.
863 \return Return channel with activity, or NULL if none has activity.
864 \param chan an array of pointers to channels
865 \param n number of channels that are to be waited upon
866 \param ms time "ms" is modified in-place, if applicable */
867 struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
869 /*! \brief Waits for input on an fd
870 This version works on fd's only. Be careful with it. */
871 int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);
874 /*! \brief Reads a frame
875 * \param chan channel to read a frame from
876 * \return Returns a frame, or NULL on error. If it returns NULL, you
877 best just stop reading frames and assume the channel has been
879 struct ast_frame *ast_read(struct ast_channel *chan);
881 /*! \brief Reads a frame, returning AST_FRAME_NULL frame if audio.
882 \param chan channel to read a frame from
883 \return Returns a frame, or NULL on error. If it returns NULL, you
884 best just stop reading frames and assume the channel has been
886 \note Audio is replaced with AST_FRAME_NULL to avoid
887 transcode when the resulting audio is not necessary. */
888 struct ast_frame *ast_read_noaudio(struct ast_channel *chan);
890 /*! \brief Write a frame to a channel
891 * This function writes the given frame to the indicated channel.
892 * \param chan destination channel of the frame
893 * \param frame frame that will be written
894 * \return It returns 0 on success, -1 on failure.
896 int ast_write(struct ast_channel *chan, struct ast_frame *frame);
898 /*! \brief Write video frame to a channel
899 * This function writes the given frame to the indicated channel.
900 * \param chan destination channel of the frame
901 * \param frame frame that will be written
902 * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
904 int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);
906 /*! \brief Write text frame to a channel
907 * This function writes the given frame to the indicated channel.
908 * \param chan destination channel of the frame
909 * \param frame frame that will be written
910 * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
912 int ast_write_text(struct ast_channel *chan, struct ast_frame *frame);
914 /*! \brief Send empty audio to prime a channel driver */
915 int ast_prod(struct ast_channel *chan);
917 /*! \brief Sets read format on channel chan
918 * Set read format for channel to whichever component of "format" is best.
919 * \param chan channel to change
920 * \param format format to change to
921 * \return Returns 0 on success, -1 on failure
923 int ast_set_read_format(struct ast_channel *chan, int format);
925 /*! \brief Sets write format on channel chan
926 * Set write format for channel to whichever component of "format" is best.
927 * \param chan channel to change
928 * \param format new format for writing
929 * \return Returns 0 on success, -1 on failure
931 int ast_set_write_format(struct ast_channel *chan, int format);
933 /*! \brief Sends text to a channel
934 * Write text to a display on a channel
935 * \param chan channel to act upon
936 * \param text string of text to send on the channel
937 * \return Returns 0 on success, -1 on failure
939 int ast_sendtext(struct ast_channel *chan, const char *text);
941 /*! \brief Receives a text character from a channel
942 * \param chan channel to act upon
943 * \param timeout timeout in milliseconds (0 for infinite wait)
944 * Read a char of text from a channel
945 * Returns 0 on success, -1 on failure
947 int ast_recvchar(struct ast_channel *chan, int timeout);
949 /*! \brief Send a DTMF digit to a channel
950 * Send a DTMF digit to a channel.
951 * \param chan channel to act upon
952 * \param digit the DTMF digit to send, encoded in ASCII
953 * \return Returns 0 on success, -1 on failure
955 int ast_senddigit(struct ast_channel *chan, char digit);
957 /*! \brief Send a DTMF digit to a channel
958 * Send a DTMF digit to a channel.
959 * \param chan channel to act upon
960 * \param digit the DTMF digit to send, encoded in ASCII
961 * \return Returns 0 on success, -1 on failure
963 int ast_senddigit_begin(struct ast_channel *chan, char digit);
965 /*! \brief Send a DTMF digit to a channel
967 * Send a DTMF digit to a channel.
968 * \param chan channel to act upon
969 * \param digit the DTMF digit to send, encoded in ASCII
970 * \param duration the duration of the digit ending in ms
971 * \return Returns 0 on success, -1 on failure
973 int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration);
975 /*! \brief Receives a text string from a channel
976 * Read a string of text from a channel
977 * \param chan channel to act upon
978 * \param timeout timeout in milliseconds (0 for infinite wait)
979 * \return the received text, or NULL to signify failure.
981 char *ast_recvtext(struct ast_channel *chan, int timeout);
983 /*! \brief Browse channels in use
984 * Browse the channels currently in use
985 * \param prev where you want to start in the channel list
986 * \return Returns the next channel in the list, NULL on end.
987 * If it returns a channel, that channel *has been locked*!
989 struct ast_channel *ast_channel_walk_locked(const struct ast_channel *prev);
991 /*! \brief Get channel by name (locks channel) */
992 struct ast_channel *ast_get_channel_by_name_locked(const char *chan);
994 /*! \brief Get channel by name prefix (locks channel) */
995 struct ast_channel *ast_get_channel_by_name_prefix_locked(const char *name, const int namelen);
997 /*! \brief Get channel by name prefix (locks channel) */
998 struct ast_channel *ast_walk_channel_by_name_prefix_locked(const struct ast_channel *chan, const char *name, const int namelen);
1000 /*! \brief Get channel by exten (and optionally context) and lock it */
1001 struct ast_channel *ast_get_channel_by_exten_locked(const char *exten, const char *context);
1003 /*! \brief Get next channel by exten (and optionally context) and lock it */
1004 struct ast_channel *ast_walk_channel_by_exten_locked(const struct ast_channel *chan, const char *exten,
1005 const char *context);
1007 /*! ! \brief Waits for a digit
1008 * \param c channel to wait for a digit on
1009 * \param ms how many milliseconds to wait
1010 * \return Returns <0 on error, 0 on no entry, and the digit on success. */
1011 int ast_waitfordigit(struct ast_channel *c, int ms);
1013 /*! \brief Wait for a digit
1014 Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
1015 * \param c channel to wait for a digit on
1016 * \param ms how many milliseconds to wait
1017 * \param audiofd audio file descriptor to write to if audio frames are received
1018 * \param ctrlfd control file descriptor to monitor for reading
1019 * \return Returns 1 if ctrlfd becomes available */
1020 int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd);
1022 /*! Reads multiple digits
1023 * \param c channel to read from
1024 * \param s string to read in to. Must be at least the size of your length
1025 * \param len how many digits to read (maximum)
1026 * \param timeout how long to timeout between digits
1027 * \param rtimeout timeout to wait on the first digit
1028 * \param enders digits to end the string
1029 * Read in a digit string "s", max length "len", maximum timeout between
1030 digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout
1031 for the first digit. Returns 0 on normal return, or 1 on a timeout. In the case of
1032 a timeout, any digits that were read before the timeout will still be available in s.
1033 RETURNS 2 in full version when ctrlfd is available, NOT 1*/
1034 int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
1035 int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);
1037 /*! \brief Report DTMF on channel 0 */
1038 #define AST_BRIDGE_DTMF_CHANNEL_0 (1 << 0)
1039 /*! \brief Report DTMF on channel 1 */
1040 #define AST_BRIDGE_DTMF_CHANNEL_1 (1 << 1)
1041 /*! \brief Return all voice frames on channel 0 */
1042 #define AST_BRIDGE_REC_CHANNEL_0 (1 << 2)
1043 /*! \brief Return all voice frames on channel 1 */
1044 #define AST_BRIDGE_REC_CHANNEL_1 (1 << 3)
1045 /*! \brief Ignore all signal frames except NULL */
1046 #define AST_BRIDGE_IGNORE_SIGS (1 << 4)
1049 /*! \brief Makes two channel formats compatible
1050 * \param c0 first channel to make compatible
1051 * \param c1 other channel to make compatible
1052 * Set two channels to compatible formats -- call before ast_channel_bridge in general .
1053 * \return Returns 0 on success and -1 if it could not be done */
1054 int ast_channel_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
1056 /*! Bridge two channels together (early)
1057 * \param c0 first channel to bridge
1058 * \param c1 second channel to bridge
1059 * Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet.
1060 * \return Returns 0 on success and -1 if it could not be done */
1061 int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
1063 /*! Bridge two channels together
1064 * \param c0 first channel to bridge
1065 * \param c1 second channel to bridge
1066 * \param config config for the channels
1067 * \param fo destination frame(?)
1068 * \param rc destination channel(?)
1069 * Bridge two channels (c0 and c1) together. If an important frame occurs, we return that frame in
1070 *rf (remember, it could be NULL) and which channel (0 or 1) in rc */
1071 /* int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); */
1072 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);
1074 /*! \brief Weird function made for call transfers
1075 * \param original channel to make a copy of
1076 * \param clone copy of the original channel
1077 * This is a very strange and freaky function used primarily for transfer. Suppose that
1078 "original" and "clone" are two channels in random situations. This function takes
1079 the guts out of "clone" and puts them into the "original" channel, then alerts the
1080 channel driver of the change, asking it to fixup any private information (like the
1081 p->owner pointer) that is affected by the change. The physical layer of the original
1082 channel is hung up. */
1083 int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone);
1085 /*! Gives the string form of a given cause code */
1087 * \param state cause to get the description of
1088 * Give a name to a cause code
1089 * Returns the text form of the binary cause code given
1091 const char *ast_cause2str(int state) attribute_pure;
1093 /*! Convert the string form of a cause code to a number */
1095 * \param name string form of the cause
1096 * Returns the cause code
1098 int ast_str2cause(const char *name) attribute_pure;
1100 /*! Gives the string form of a given channel state */
1102 * \param ast_channel_state state to get the name of
1103 * Give a name to a state
1104 * Returns the text form of the binary state given
1106 const char *ast_state2str(enum ast_channel_state);
1108 /*! Gives the string form of a given transfer capability */
1110 * \param transfercapability transfercapabilty to get the name of
1111 * Give a name to a transfercapbility
1113 * Returns the text form of the binary transfer capbaility
1115 char *ast_transfercapability2str(int transfercapability) attribute_const;
1117 /* Options: Some low-level drivers may implement "options" allowing fine tuning of the
1118 low level channel. See frame.h for options. Note that many channel drivers may support
1119 none or a subset of those features, and you should not count on this if you want your
1120 asterisk application to be portable. They're mainly useful for tweaking performance */
1122 /*! Sets an option on a channel */
1124 * \param channel channel to set options on
1125 * \param option option to change
1126 * \param data data specific to option
1127 * \param datalen length of the data
1128 * \param block blocking or not
1129 * Set an option on a channel (see frame.h), optionally blocking awaiting the reply
1130 * Returns 0 on success and -1 on failure
1132 int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);
1134 /*! Pick the best codec */
1135 /* Choose the best codec... Uhhh... Yah. */
1136 int ast_best_codec(int fmts);
1139 /*! Checks the value of an option */
1141 * Query the value of an option, optionally blocking until a reply is received
1142 * Works similarly to setoption except only reads the options.
1144 struct ast_frame *ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);
1146 /*! Checks for HTML support on a channel */
1147 /*! Returns 0 if channel does not support HTML or non-zero if it does */
1148 int ast_channel_supports_html(struct ast_channel *channel);
1150 /*! Sends HTML on given channel */
1151 /*! Send HTML or URL on link. Returns 0 on success or -1 on failure */
1152 int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);
1154 /*! Sends a URL on a given link */
1155 /*! Send URL on link. Returns 0 on success or -1 on failure */
1156 int ast_channel_sendurl(struct ast_channel *channel, const char *url);
1159 /*! Defer DTMF so that you only read things like hangups and audio. Returns
1160 non-zero if channel was already DTMF-deferred or 0 if channel is just now
1161 being DTMF-deferred */
1162 int ast_channel_defer_dtmf(struct ast_channel *chan);
1164 /*! Undo defer. ast_read will return any dtmf characters that were queued */
1165 void ast_channel_undefer_dtmf(struct ast_channel *chan);
1167 /*! Initiate system shutdown -- prevents new channels from being allocated.
1168 If "hangup" is non-zero, all existing channels will receive soft
1170 void ast_begin_shutdown(int hangup);
1172 /*! Cancels an existing shutdown and returns to normal operation */
1173 void ast_cancel_shutdown(void);
1175 /*! Returns number of active/allocated channels */
1176 int ast_active_channels(void);
1178 /*! Returns non-zero if Asterisk is being shut down */
1179 int ast_shutting_down(void);
1181 /*! Activate a given generator */
1182 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);
1184 /*! Deactivate an active generator */
1185 void ast_deactivate_generator(struct ast_channel *chan);
1187 void ast_set_callerid(struct ast_channel *chan, const char *cidnum, const char *cidname, const char *ani);
1189 /*! Start a tone going */
1190 int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
1191 /*! Stop a tone from playing */
1192 void ast_tonepair_stop(struct ast_channel *chan);
1193 /*! Play a tone pair for a given amount of time */
1194 int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
1197 * \brief Automatically service a channel for us...
1200 * \retval -1 failure, or the channel is already being autoserviced
1202 int ast_autoservice_start(struct ast_channel *chan);
1205 * \brief Stop servicing a channel for us...
1208 * \retval -1 error, or the channel has been hungup
1210 int ast_autoservice_stop(struct ast_channel *chan);
1212 /* If built with zaptel optimizations, force a scheduled expiration on the
1213 timer fd, at which point we call the callback function / data */
1214 int ast_settimeout(struct ast_channel *c, int samples, int (*func)(void *data), void *data);
1216 /*! \brief Transfer a channel (if supported). Returns -1 on error, 0 if not supported
1217 and 1 if supported and requested
1218 \param chan current channel
1219 \param dest destination extension for transfer
1221 int ast_transfer(struct ast_channel *chan, char *dest);
1223 /*! \brief Start masquerading a channel
1224 XXX This is a seriously whacked out operation. We're essentially putting the guts of
1225 the clone channel into the original channel. Start by killing off the original
1226 channel's backend. I'm not sure we're going to keep this function, because
1227 while the features are nice, the cost is very high in terms of pure nastiness. XXX
1228 \param chan Channel to masquerade
1230 int ast_do_masquerade(struct ast_channel *chan);
1232 /*! \brief Find bridged channel
1233 \param chan Current channel
1235 struct ast_channel *ast_bridged_channel(struct ast_channel *chan);
1238 \brief Inherits channel variable from parent to child channel
1239 \param parent Parent channel
1240 \param child Child channel
1242 Scans all channel variables in the parent channel, looking for those
1243 that should be copied into the child channel.
1244 Variables whose names begin with a single '_' are copied into the
1245 child channel with the prefix removed.
1246 Variables whose names begin with '__' are copied into the child
1247 channel with their names unchanged.
1249 void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);
1252 \brief adds a list of channel variables to a channel
1253 \param chan the channel
1254 \param vars a linked list of variables
1256 Variable names can be for a regular channel variable or a dialplan function
1257 that has the ability to be written to.
1259 void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);
1262 \brief An opaque 'object' structure use by silence generators on channels.
1264 struct ast_silence_generator;
1267 \brief Starts a silence generator on the given channel.
1268 \param chan The channel to generate silence on
1269 \return An ast_silence_generator pointer, or NULL if an error occurs
1271 This function will cause SLINEAR silence to be generated on the supplied
1272 channel until it is disabled; if the channel cannot be put into SLINEAR
1273 mode then the function will fail.
1275 The pointer returned by this function must be preserved and passed to
1276 ast_channel_stop_silence_generator when you wish to stop the silence
1279 struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);
1282 \brief Stops a previously-started silence generator on the given channel.
1283 \param chan The channel to operate on
1284 \param state The ast_silence_generator pointer return by a previous call to
1285 ast_channel_start_silence_generator.
1288 This function will stop the operating silence generator and return the channel
1289 to its previous write format.
1291 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);
1294 \brief Check if the channel can run in internal timing mode.
1295 \param chan The channel to check
1298 This function will return 1 if internal timing is enabled and the timing
1299 device is available.
1301 int ast_internal_timing_enabled(struct ast_channel *chan);
1303 /* Misc. functions below */
1305 /*! \brief if fd is a valid descriptor, set *pfd with the descriptor
1306 * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the
1307 * return value to the index into the array)
1309 static inline int ast_add_fd(struct pollfd *pfd, int fd)
1312 pfd->events = POLLIN | POLLPRI;
1316 /*! \brief Helper function for migrating select to poll */
1317 static inline int ast_fdisset(struct pollfd *pfds, int fd, int max, int *start)
1326 for (x = *start; x<max; x++)
1327 if (pfds[x].fd == fd) {
1330 return pfds[x].revents;
1336 static inline void timersub(struct timeval *tvend, struct timeval *tvstart, struct timeval *tvdiff)
1338 tvdiff->tv_sec = tvend->tv_sec - tvstart->tv_sec;
1339 tvdiff->tv_usec = tvend->tv_usec - tvstart->tv_usec;
1340 if (tvdiff->tv_usec < 0) {
1342 tvdiff->tv_usec += 1000000;
1348 /*! \brief Waits for activity on a group of channels
1349 * \param nfds the maximum number of file descriptors in the sets
1350 * \param rfds file descriptors to check for read availability
1351 * \param wfds file descriptors to check for write availability
1352 * \param efds file descriptors to check for exceptions (OOB data)
1353 * \param tvp timeout while waiting for events
1354 * This is the same as a standard select(), except it guarantees the
1355 * behaviour where the passed struct timeval is updated with how much
1356 * time was not slept while waiting for the specified events
1358 static inline int ast_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tvp)
1361 return select(nfds, rfds, wfds, efds, tvp);
1364 struct timeval tv, tvstart, tvend, tvlen;
1368 gettimeofday(&tvstart, NULL);
1369 res = select(nfds, rfds, wfds, efds, tvp);
1370 gettimeofday(&tvend, NULL);
1371 timersub(&tvend, &tvstart, &tvlen);
1372 timersub(&tv, &tvlen, tvp);
1373 if (tvp->tv_sec < 0 || (tvp->tv_sec == 0 && tvp->tv_usec < 0)) {
1380 return select(nfds, rfds, wfds, efds, NULL);
1385 #define CRASH do { fprintf(stderr, "!! Forcing immediate crash a-la abort !!\n"); *((int *)0) = 0; } while(0)
1387 #define CRASH do { } while(0)
1390 #define CHECK_BLOCKING(c) do { \
1391 if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\
1393 ast_log(LOG_DEBUG, "Thread %ld Blocking '%s', already blocked by thread %ld in procedure %s\n", (long) pthread_self(), (c)->name, (long) (c)->blocker, (c)->blockproc); \
1396 (c)->blocker = pthread_self(); \
1397 (c)->blockproc = __PRETTY_FUNCTION__; \
1398 ast_set_flag(c, AST_FLAG_BLOCKING); \
1401 ast_group_t ast_get_group(const char *s);
1403 /*! \brief print call- and pickup groups into buffer */
1404 char *ast_print_group(char *buf, int buflen, ast_group_t group);
1406 /*! \brief Convert enum channelreloadreason to text string for manager event
1407 \param reason Enum channelreloadreason - reason for reload (manager, cli, start etc)
1409 const char *channelreloadreason2txt(enum channelreloadreason reason);
1411 /*! \brief return an ast_variable list of channeltypes */
1412 struct ast_variable *ast_channeltype_list(void);
1415 \brief Begin 'whispering' onto a channel
1416 \param chan The channel to whisper onto
1417 \return 0 for success, non-zero for failure
1419 This function will add a whisper buffer onto a channel and set a flag
1420 causing writes to the channel to reduce the volume level of the written
1421 audio samples, and then to mix in audio from the whisper buffer if it
1424 \note Note: This function performs no locking; you must hold the channel's lock before
1425 calling this function.
1427 int ast_channel_whisper_start(struct ast_channel *chan);
1430 \brief Feed an audio frame into the whisper buffer on a channel
1431 \param chan The channel to whisper onto
1432 \param f The frame to to whisper onto chan
1433 \return 0 for success, non-zero for failure
1435 int ast_channel_whisper_feed(struct ast_channel *chan, struct ast_frame *f);
1438 \brief Stop 'whispering' onto a channel
1439 \param chan The channel to whisper onto
1440 \return 0 for success, non-zero for failure
1442 Note: This function performs no locking; you must hold the channel's lock before
1443 calling this function.
1445 void ast_channel_whisper_stop(struct ast_channel *chan);
1447 #if defined(__cplusplus) || defined(c_plusplus)
1451 #endif /* _ASTERISK_CHANNEL_H */