📄 channel.h
字号:
/* * Asterisk -- An open source telephony toolkit. * * Copyright (C) 1999 - 2006, Digium, Inc. * * Mark Spencer <markster@digium.com> * * See http://www.asterisk.org for more information about * the Asterisk project. Please do not directly contact * any of the maintainers of this project for assistance; * the project provides a web site, mailing lists and IRC * channels for your use. * * This program is free software, distributed under the terms of * the GNU General Public License Version 2. See the LICENSE file * at the top of the source tree. *//*! \file * \brief General Asterisk PBX channel definitions. * \par See also: * \arg \ref Def_Channel * \arg \ref channel_drivers *//*! \page Def_Channel Asterisk Channels \par What is a Channel? A phone call through Asterisk consists of an incoming connection and an outbound connection. Each call comes in through a channel driver that supports one technology, like SIP, DAHDI, IAX2 etc. \par Each channel driver, technology, has it's own private channel or dialog structure, that is technology-dependent. Each private structure is "owned" by a generic Asterisk channel structure, defined in channel.h and handled by channel.c . \par Call scenario This happens when an incoming call arrives to Asterisk -# Call arrives on a channel driver interface -# Channel driver creates a PBX channel and starts a pbx thread on the channel -# The dial plan is executed -# At this point at least two things can happen: -# The call is answered by Asterisk and Asterisk plays a media stream or reads media -# The dial plan forces Asterisk to create an outbound call somewhere with the dial (see \ref app_dial.c) application . \par Bridging channels If Asterisk dials out this happens: -# Dial creates an outbound PBX channel and asks one of the channel drivers to create a call -# When the call is answered, Asterisk bridges the media streams so the caller on the first channel can speak with the callee on the second, outbound channel -# In some cases where we have the same technology on both channels and compatible codecs, a native bridge is used. In a native bridge, the channel driver handles forwarding of incoming audio to the outbound stream internally, without sending audio frames through the PBX. -# In SIP, theres an "external native bridge" where Asterisk redirects the endpoint, so audio flows directly between the caller's phone and the callee's phone. Signalling stays in Asterisk in order to be able to provide a proper CDR record for the call. \par Masquerading channels In some cases, a channel can masquerade itself into another channel. This happens frequently in call transfers, where a new channel takes over a channel that is already involved in a call. The new channel sneaks in and takes over the bridge and the old channel, now a zombie, is hung up. \par Reference \arg channel.c - generic functions \arg channel.h - declarations of functions, flags and structures \arg translate.h - Transcoding support functions \arg \ref channel_drivers - Implemented channel drivers \arg \ref Def_Frame Asterisk Multimedia Frames \arg \ref Def_Bridge*//*! \page Def_Bridge Asterisk Channel Bridges In Asterisk, there's several media bridges. The Core bridge handles two channels (a "phone call") and bridge them together. The conference bridge (meetme) handles several channels simultaneously with the support of an external timer (DAHDI timer). This is used not only by the Conference application (meetme) but also by the page application and the SLA system introduced in 1.4. The conference bridge does not handle video. When two channels of the same type connect, the channel driver or the media subsystem used by the channel driver (i.e. RTP) can create a native bridge without sending media through the core. Native briding can be disabled by a number of reasons, like DTMF being needed by the core or codecs being incompatible so a transcoding module is needed.References: \li \see ast_channel_early_bridge() \li \see ast_channel_bridge() \li \see app_meetme.c \li \ref AstRTPbridge \li \see ast_rtp_bridge() \li \ref Def_Channel*//*! \page AstFileDesc File descriptors Asterisk File descriptors are connected to each channel (see \ref Def_Channel) in the \ref ast_channel structure.*/#ifndef _ASTERISK_CHANNEL_H#define _ASTERISK_CHANNEL_H#include "asterisk/abstract_jb.h"#ifdef HAVE_SYS_POLL_H#include <sys/poll.h>#else#include "asterisk/poll-compat.h"#endif#if defined(__cplusplus) || defined(c_plusplus)extern "C" {#endif#define AST_MAX_EXTENSION 80 /*!< Max length of an extension */#define AST_MAX_CONTEXT 80 /*!< Max length of a context */#define AST_CHANNEL_NAME 80 /*!< Max length of an ast_channel name */#define MAX_LANGUAGE 20 /*!< Max length of the language setting */#define MAX_MUSICCLASS 80 /*!< Max length of the music class setting */#include "asterisk/frame.h"#include "asterisk/sched.h"#include "asterisk/chanvars.h"#include "asterisk/config.h"#include "asterisk/lock.h"#include "asterisk/cdr.h"#include "asterisk/utils.h"#include "asterisk/linkedlists.h"#include "asterisk/stringfields.h"#define DATASTORE_INHERIT_FOREVER INT_MAX#define AST_MAX_FDS 10/* * We have AST_MAX_FDS file descriptors in a channel. * Some of them have a fixed use: */#define AST_ALERT_FD (AST_MAX_FDS-1) /*!< used for alertpipe */#define AST_TIMING_FD (AST_MAX_FDS-2) /*!< used for timingfd */#define AST_AGENT_FD (AST_MAX_FDS-3) /*!< used by agents for pass through */#define AST_GENERATOR_FD (AST_MAX_FDS-4) /*!< used by generator */enum ast_bridge_result { AST_BRIDGE_COMPLETE = 0, AST_BRIDGE_FAILED = -1, AST_BRIDGE_FAILED_NOWARN = -2, AST_BRIDGE_RETRY = -3,};typedef unsigned long long ast_group_t;/*! \todo Add an explanation of an Asterisk generator */struct ast_generator { void *(*alloc)(struct ast_channel *chan, void *params); void (*release)(struct ast_channel *chan, void *data); /*! This function gets called with the channel unlocked, but is called in * the context of the channel thread so we know the channel is not going * to disappear. This callback is responsible for locking the channel as * necessary. */ int (*generate)(struct ast_channel *chan, void *data, int len, int samples); /*! This gets called when DTMF_END frames are read from the channel */ void (*digit)(struct ast_channel *chan, char digit);};/*! \brief Structure for a data store type */struct ast_datastore_info { const char *type; /*!< Type of data store */ void *(*duplicate)(void *data); /*!< Duplicate item data (used for inheritance) */ void (*destroy)(void *data); /*!< Destroy function */ /*! * \brief Fix up channel references * * \arg data The datastore data * \arg old_chan The old channel owning the datastore * \arg new_chan The new channel owning the datastore * * This is exactly like the fixup callback of the channel technology interface. * It allows a datastore to fix any pointers it saved to the owning channel * in case that the owning channel has changed. Generally, this would happen * when the datastore is set to be inherited, and a masquerade occurs. * * \return nothing. */ void (*chan_fixup)(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan);};/*! \brief Structure for a channel data store */struct ast_datastore { const char *uid; /*!< Unique data store identifier */ void *data; /*!< Contained data */ const struct ast_datastore_info *info; /*!< Data store type information */ unsigned int inheritance; /*!< Number of levels this item will continue to be inherited */ AST_LIST_ENTRY(ast_datastore) entry; /*!< Used for easy linking */};/*! \brief Structure for all kinds of caller ID identifications. * \note All string fields here are malloc'ed, so they need to be * freed when the structure is deleted. * Also, NULL and "" must be considered equivalent. * * SIP and IAX2 has utf8 encoded Unicode caller ID names. * In some cases, we also have an alternative (RPID) E.164 number that can be used * as caller ID on numeric E.164 phone networks (DAHDI or SIP/IAX2 to pstn gateway). * * \todo Implement settings for transliteration between UTF8 caller ID names in * to Ascii Caller ID's (DAHDI). 謘ten 舠klund might be transliterated into * Osten Asklund or Oesten Aasklund depending upon language and person... * We need automatic routines for incoming calls and static settings for * our own accounts. */struct ast_callerid { char *cid_dnid; /*!< Malloc'd Dialed Number Identifier */ char *cid_num; /*!< Malloc'd Caller Number */ char *cid_name; /*!< Malloc'd Caller Name (ASCII) */ char *cid_ani; /*!< Malloc'd ANI */ char *cid_rdnis; /*!< Malloc'd RDNIS */ int cid_pres; /*!< Callerid presentation/screening */ int cid_ani2; /*!< Callerid ANI 2 (Info digits) */ int cid_ton; /*!< Callerid Type of Number */ int cid_tns; /*!< Callerid Transit Network Select */};/*! \brief Structure to describe a channel "technology", ie a channel driver See for examples: \arg chan_iax2.c - The Inter-Asterisk exchange protocol \arg chan_sip.c - The SIP channel driver \arg chan_dahdi.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS) If you develop your own channel driver, this is where you tell the PBX at registration of your driver what properties this driver supports and where different callbacks are implemented.*/struct ast_channel_tech { const char * const type; const char * const description; int capabilities; /*!< Bitmap of formats this channel can handle */ int properties; /*!< Technology Properties */ /*! \brief Requester - to set up call data structures (pvt's) */ struct ast_channel *(* const requester)(const char *type, int format, void *data, int *cause); int (* const devicestate)(void *data); /*!< Devicestate call back */ /*! * \brief Start sending a literal DTMF digit * * \note The channel is not locked when this function gets called. */ int (* const send_digit_begin)(struct ast_channel *chan, char digit); /*! * \brief Stop sending a literal DTMF digit * * \note The channel is not locked when this function gets called. */ int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration); /*! \brief Call a given phone number (address, etc), but don't take longer than timeout seconds to do so. */ int (* const call)(struct ast_channel *chan, char *addr, int timeout); /*! \brief Hangup (and possibly destroy) the channel */ int (* const hangup)(struct ast_channel *chan); /*! \brief Answer the channel */ int (* const answer)(struct ast_channel *chan); /*! \brief Read a frame, in standard format (see frame.h) */ struct ast_frame * (* const read)(struct ast_channel *chan); /*! \brief Write a frame, in standard format (see frame.h) */ int (* const write)(struct ast_channel *chan, struct ast_frame *frame); /*! \brief Display or transmit text */ int (* const send_text)(struct ast_channel *chan, const char *text); /*! \brief Display or send an image */ int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame); /*! \brief Send HTML data */ int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len); /*! \brief Handle an exception, reading a frame */ struct ast_frame * (* const exception)(struct ast_channel *chan); /*! \brief Bridge two channels of the same type together */ enum ast_bridge_result (* const bridge)(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms); /*! \brief Bridge two channels of the same type together (early) */ enum ast_bridge_result (* const early_bridge)(struct ast_channel *c0, struct ast_channel *c1); /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */ int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen); /*! \brief Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links */ int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan); /*! \brief Set a given option */ int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen); /*! \brief Query a given option */ int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen); /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */ int (* const transfer)(struct ast_channel *chan, const char *newdest); /*! \brief Write a frame, in standard format */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -