ASTERISK[1]

Source: Internet
Author: User

Asterisk [1] is a GPLv2 Open Source Telephony Application platform under the agreement. Simply put,Asterisk is a server application that can make phone calls, accept phone calls, and customize phone calls.

1.2.1 Channel Drive

Asterisk the channel-driven interface is the most complex and the most important available interface. The Asteisk Channel API provides an abstraction of a variety of communication protocols, making the various features of Asterisk not necessarily concerned with specific communication protocols. This component is primarily responsible for communication in the asterisk channel abstraction and in the implementation of the specific communication protocol.

Asterisk the channel-driven interface is defined as the Ast_channel_tech interface. This interface defines a number of methods that the channel driver must implement. The first way to implement the channel driver is to ast_channel the factory method, which is the requester in Ast_channel_tech. When a asterisk channel is created, regardless of whether the channel is incoming direction or outgoing direction, the Ast_channel_tech implementation associated with that channel is responsible for instantiating and initializing the Ast_channel for that road call.

Ast_channel once created, the structure has a ast_channel_tech pointer that creates the channel . Of course, there are many other operations that need to be handled in a way that is technically relevant. Figure 1.2 shows the two channels in the asterisk, and figure 1.4 expands to show two bridged channels and how channel technology is implemented.

The most important methods in Ast_channel_tech include:

requester: used to drive a request to a channel and instantiate a Ast_channel object to perform the appropriate initialization work based on the channel type.

Call: The user initiates an outbound call to the terminal represented by Ast_channel.

Answer: Called when Asterisk decides that the incoming call to the Ast_channel association should be answered.

hangup: Called when the system determines that the current call should hang. The channel driver needs to communicate with the terminal in accordance with a certain protocol.

indicate: after the call has started, there are other events that need to be notified to the terminal. For example, if the device is held, the function is called.

send_digit_begin: This function is called when the terminal device starts to send the key DTMF to the asterisk.

send_digit_end: This function is called when the terminal device sends a key to the asterisk DTMF end.

read: call the Read function when the asterisk core needs to read a Ast_frame data frame from the terminal. Ast_frame frames are abstract structures used in asterisk to encapsulate media (such as audio or video) and signals.

Write: Use this function to send a ast_frame frame to the end device. Typically, channel-driven data processing (acquisition, etc.) and packaging make the packet suitable for the communication protocol used, and then send the packaged data to the terminal.

Bridge: The local bridging function in the channel type. As mentioned earlier, a local bridge is a channel driver that provides a more efficient bridging method for two channels of the same type, rather than having all the signaling and media streams through an additional abstraction layer. This is extremely important for providing performance.

after the call is over, the abstract channel processing code in the asterisk core invokes the Hangup function in Ast_channel_tech and then destroys the Ast_channel object.

1.1.2 Channel Bridging

a more familiar call scene is a connection between two telephones. In this scenario, there are two telephone terminals connected to the asterisk system, so there are two channels in this call.

Figure 1.2 Two call leg, representing two channels

showing two channels in the asterisk, figure 1.4 expands to show two bridged channels and how channel technology is implemented.

Figure 1.4 channel technology and channel abstraction layer

before we go into the example, let's take a look at the syntax for handling call 1234 in the asterisk dialing scheme.

Note that the 1234 number is random.

after calling the number, 3 dialing scheme applications were called,

First answer the call, then play a sound file, and finally hang up the call.

; Define The rules forwhat happens when someone dials 1234. ;

Exten = 1234,1,answer ()

Same=> N,playback (demo-congrats)

same = N,hangup (). Csharpcode,. Csharpcode

Pre {font-size:small; Color:black;font-family:consolas, "Courier New", Courier, Monospace;background-color: #ffffff; *white-space:pre;*/}. csharpcode pre {margin:0em;}. csharpcode. rem {color: #008000;}. Csharpcode. kwrd {color: #00 00FF;} . csharpcode str {color: #006080;}. Csharpcode. op {color: #0000c0;}. Csharpcode. Preproc {color: #cc6633;}. Csharpcode. asp {background-color: #ffff00;}. csharpcode. html {color: #800000; }. Csharpcode. attr {color: #ff0000;}. Csharpcode. alt {background-color: #f4f4f4; width:100%; margin:0em;}. Csharpco De. lnum {color: #606060;}

Exten The keyword is used to define extension .

on the right side of the Exten line, 1234 is the call rule defined for the number called 1234.

The following 1 is the first step to take when dialing the number 1234 , Answer is telling the system to answer the call. The following two lines, which begin with the same keyword , are defined by the extension next rule, which is the next rule of 1234.

N is the next action to take , the following entries indicate the specific actions to be performed by the dial plan.

1.1.1 Channel

1.1.2 Channel Bridging

a more familiar call scene is a connection between two telephones. In this scenario, there are two telephone terminals connected to the asterisk system, so there are two channels in this call.

Figure 1.2 Two call leg, representing two channels

when the asterisk channel is connected as above, it is called a channel bridge. The two channels are bridged after the channel bridge is executed to allow media information to be passed between the two channels

All media streams are negotiated through Asterisk . Asterisk can be used for recording, audio operation, and transcoding between different technologies.

two channels are bridged together and can be done in the following two ways: Universal bridging and local bridging. Universal bridging is the ability to work properly regardless of the channel technology used, which transmits all audio and signaling data through the asterisk Abstraction channel interface. This bridging method is the most complex and most effective.

local bridging is a bridge that is related to the technology used by the call. If two channels use the same media transfer technology, it can be done in a more efficient way rather than through the asterisk abstraction Layer , as in different technologies.

decide whether to use a universal bridge or a local bridge is done by comparing two channels when bridging . If the two channels support local bridging, the local bridge is used, whereas the generic bridging is employed instead. To determine whether the two channels support the same local bridging method, a simple comparison of C function pointers is possible . This comparison is not the most elegant method, but we have not met the situation that does not meet our needs. The local bridging of the channel will be discussed in the 1.2 section. Figure 1.3 illustrates an example of a local bridge.

Figure 3 local bridging

1.1.3 Frame

The communication of a call in the asterisk code is done by using frames. A frame is an instance of a data structure ast_frame.

Asterisk The list of frame types supported in is statically defined, and each type of frame is identified by a digitally encoded type (type) and subtype (subtype). For a complete list of frame types in the Include/asterisk/frame.h file, some examples are as follows:

· Voice: These frames carry a portion of the voice stream

· Video: These frames carry a portion of the stream

· MODEM: The encoding of the data in this frame, such as t.38, is sent by IP network to fax. This type of frame is primarily used to process faxes. It is important to note that this data frame, must be continuous can not be interrupted, to ensure that the end of the data can be correctly decoded. This differs from the audio frame in that the audio frame can be transcoded with a different encoding, while sacrificing audio quality but saving network bandwidth.

· CONTROL: This frame includes the signaling message for the call. These frames are usually used to describe the call signaling time, including telephone connection, hang-off, hold, etc.

· Dtmf_begin: The number starts at the beginning. This kind of frame is usually the caller on the telephone to start pressing a DTMF button. ( dual tone Multi-frequency:dual-tonemultifrequency Dual-tone multi-frequency DTMF)

· Dtmf_end: where the numbers end. This frame is the DTMF key of the caller on the end of the telephone.

1.2 Asterisk Component Abstraction

Asterisk is a highly modular application. Includes a core application that can be built by compiling the main directory of the asterisk code tree. However, the core of light is usually of little use. Core applications mainly deal with module registration, there is also code including how to connect the abstract interface to complete telephone calls. The specific implementation interface is done through modules that can be loaded into the system at runtime.

by default, all modules are placed in the asterisk pre-defined module file directory, and all modules in that directory are loaded by the main app when it is started. The reason for this design is to keep it simple. There is also a configuration file in asterisk that allows you to define the loaded modules and the order in which the modules are loaded. This may seem a bit cumbersome to configure, but it allows the user to specify which modules do not need to be loaded. The biggest benefit is to reduce the memory footprint of your application and, of course, to help improve your system's security. The best practice is not to load modules that accept network connections if they are not very much needed.

when the module is loaded, the component abstraction interface implemented by this module is registered with the Asterisk master application. There are several types of interfaces that modules can implement and register with the asterisk core. Typically, the associated functionality is placed in a module.

1.2.1 Channel Drive

Asterisk the channel-driven interface is the most complex and the most important available interface. The Asteisk Channel API provides an abstraction of a variety of communication protocols, making the various features of Asterisk not necessarily concerned with specific communication protocols. This component is primarily responsible for communication in the asterisk channel abstraction and in the implementation of the specific communication protocol.

Asterisk the channel-driven interface is defined as the Ast_channel_tech interface. This interface defines a number of methods that the channel driver must implement. The first way to implement the channel driver is to ast_channel the factory method, which is the requester in Ast_channel_tech. When a asterisk channel is created, regardless of whether the channel is incoming direction or outgoing direction, the Ast_channel_tech implementation associated with that channel is responsible for instantiating and initializing the Ast_channel for that road call.

Ast_channel once created, the structure has a ast_channel_tech pointer that creates the channel . Of course, there are many other operations that need to be handled in a way that is technically relevant. Figure 1.2 shows the two channels in the asterisk, and figure 1.4 expands to show two bridged channels and how channel technology is implemented.

Figure 1.4 channel technology and channel abstraction layer

The most important methods in Ast_channel_tech include:

requester: used to drive a request to a channel and instantiate a Ast_channel object to perform the appropriate initialization work based on the channel type.

Call: The user initiates an outbound call to the terminal represented by Ast_channel.

Answer: Called when Asterisk decides that the incoming call to the Ast_channel association should be answered.

hangup: Called when the system determines that the current call should hang. The channel driver needs to communicate with the terminal in accordance with a certain protocol.

indicate: after the call has started, there are other events that need to be notified to the terminal. For example, if the device is held, the function is called.

send_digit_begin: This function is called when the terminal device starts to send the key DTMF to the asterisk.

send_digit_end: This function is called when the terminal device sends a key to the asterisk DTMF end.

read: call the Read function when the asterisk core needs to read a Ast_frame data frame from the terminal. Ast_frame frames are abstract structures used in asterisk to encapsulate media (such as audio or video) and signals.

Write: Use this function to send a ast_frame frame to the end device. Typically, channel-driven data processing (acquisition, etc.) and packaging make the packet suitable for the communication protocol used, and then send the packaged data to the terminal.

Bridge: The local bridging function in the channel type. As mentioned earlier, a local bridge is a channel driver that provides a more efficient bridging method for two channels of the same type, rather than having all the signaling and media streams through an additional abstraction layer. This is extremely important for providing performance.

after the call is over, the abstract channel processing code in the asterisk core invokes the Hangup function in Ast_channel_tech and then destroys the Ast_channel object.

1.2.2 dial-up apps

Asterisk The administrator sets up call routing through Dial Planning in /etc/asterisk/extensions.conf . A dialing scheme is a series of call routing rules (called extension). After the phone call enters the system, the system uses the called number to find the corresponding extension in the dialing scheme that the call should use. The extension includes a series of dial-up scheme applications that can be performed on the channel. The apps used in the dial plan are maintained by the application registration mechanism in asterisk. The registration of the application is done when the corresponding module is loaded.

through Asterisk dialing scheme, multiple apps can be used together to customize the process of calling. For complex customizations that cannot be done using the provided dial-up scheme,\

1.2.4 Encoding Conversion

in the VoIP world, we use a number of different encodings to encode the media and send the encoded data to the network. There is a lot of coding to choose from, but there are sacrifices in media quality, CPU consumption, and bandwidth requirements. The asterisk supports a number of different compression encodings, and can be converted between encoded formats when necessary.

when the call is established, Asterisk tries to have two terminals use the same media encoding format, so that transcoding is not required. However, this is just the ideal situation. Even with a common code, transcoding is still needed. For example, if you configure the asterisk to signal processing of your system's audio data, such as increasing or decreasing the volume. Asterisk can also be configured for call recording, if the configuration of the format of the recording file and call encoding format inconsistent, still need to encode.

Description: Encoding Negotiation

The method used to negotiate the encoding of the media stream is deterministic for the various techniques used to connect to the asterisk. There are times when, for example, calls through a traditional telephone network do not require any negotiation. However, in other cases, in particular the use of IP protocols, it is necessary to use a negotiation mechanism to negotiate a common encoding by describing the capabilities of the terminal and the preferred encoding.

take the SIP protocol as an example, here is how the call to asterisk after the code negotiation.

Description: Encoding Negotiation

The method used to negotiate the encoding of the media stream is deterministic for the various techniques used to connect to the asterisk. There are times when, for example, calls through a traditional telephone network do not require any negotiation. However, in other cases, in particular the use of IP protocols, it is necessary to use a negotiation mechanism to negotiate a common encoding by describing the capabilities of the terminal and the preferred encoding.

take the SIP protocol as an example, here is how the call to asterisk after the code negotiation.

1. The terminal initiates a call request to Asterisk , which contains the encoding format that the terminal wishes to use.

2.Asterisk Select a top-priority encoding by querying the administrator's configured speech encoding precedence, which is both the encoding of the asterisk precedence table and the terminal's support.

Asterisk The coding process is not very good for more complex coding, especially video coding. The need for coding negotiations has been very complex over the past ten years. We still have a lot of work to do to better handle new audio coding and to better support video coding. This is a new requirement in the asterisk release.

The encoding Conversion module provides an implementation of one or more ast_translator interfaces. The encoding Converter has the source and destination formatting attributes, and provides a callback function that can complete the conversion of a piece of media information from the source format to the destination format. The encoding converter itself is unaware of the call itself, and all it needs to know is how to complete the conversion of the media from one format to another.

For more information about the converter API , refer to Include/asterisk/translate.h and main/translate.c. The implementation of the converter abstraction can be found in the codecs directory.

ASTERISK[1]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.