Asterisk RTP Engine

Source: Internet
Author: User

The asterisk kernel (hereinafter referred to as the kernel) provides a series of RTP-related API functions. When using different RTP stacks, these Apis provide a unified access method for the RTP module. After these APIs are encapsulated, any module using RTP will not feel the difference between the underlying stack. For modules, the behavior of each RTP stack is the same.

The kernel calls an RTP session an RTP instance. An instance consists of several components: codec information, RTP engine, RTP attribute information, and address information. You can use the engine name to specify the used RTP stack. If no RTP stack is specified, the default stack is used. The caller can provide the address used by RTP, but the underlying RTP engine may select an appropriate address based on its own configuration.

The RTP engine (usually a module classified by resource) is a layer between the kernel and the RTP stack. The kernel provides a series of callback interfaces to complete different transactions (such as audio output), and the RTP engine needs to adapt to these interfaces, that is, encapsulate the RTP stack.

Glue is the content bound between an RTP instance and a channel. When a remote bridge or local bridge is executed, or the channel driver needs to notify the remote end to change the destination of the RTP stream, it is used to retrieve the RTP instance.

You can call the ast_rtp_instance_get_stats API to retrieve the statistics of RTP instances. This requires that the RTP engine in use fill in a data structure to carry the requested statistical item value. No RTP engine is required to support all statistics.

The caller can change the behaviors of the RTP engine and core, which requires setting the RTP attribute. For example, an attribute called ast_rtp_property_nat is used to tell the RTP engine to enable symmetric RTP. The kernel does not require a RTP engine to support all attributes.

Codec information is stored in an independent data structure. It has its own set of APIS for addition, deletion, or information retrieval. Use their modules and call these Apis after the RTP instance is created. In this way, the load information is visible to the RTP engine.

 

Data Structure

Ast_rtp_instance, which describes the data structure of rtpsession.

00048 /*! Structure that represents an RTP session (instance) */
00049 struct ast_rtp_instance {
00050    /*! Engine that is handling this RTP instance */
00051    struct ast_rtp_engine *engine;
00052    /*! Data unique to the RTP engine */
00053    void *data;
00054    /*! RTP properties that have been set and their value */
00055    int properties[AST_RTP_PROPERTY_MAX];
00056    /*! Address that we are expecting RTP to come in to */
00057    struct ast_sockaddr local_address;
           ........
 };

 

 

Ast_rtp_mime_type. In rtp_engine.c, an array is defined to describe the mime media type.

00086 /*! The following array defines the MIME Media type (and subtype) for each
00087    of our codecs, or RTP-specific data type. */
00088 static struct ast_rtp_mime_type {
00089    struct ast_rtp_payload_type payload_type;
00090    char *type;
00091    char *subtype;
00092    unsigned int sample_rate;
00093 } ast_rtp_mime_types[]; 

 

 

Ast_rtp_engine describes the data structure of a specific RTP stack and provides a series of interface definitions for the interaction between the kernel and the RTP stack. The specific RTP engine must be instantiated.

00313 /*! Structure that represents an RTP stack (engine) */
00314 struct ast_rtp_engine {
00315    /*! Name of the RTP engine, used when explicitly requested */
00316    const char *name;
00317    /*! Module this RTP engine came from, used for reference counting */
00318    struct ast_module *mod;
00319    /*! Callback for setting up a new RTP instance */
00320    int (*new)(struct ast_rtp_instance *instance, struct ast_sched_context *sched, struct ast_sockaddr *sa, void *data);
00321    /*! Callback for destroying an RTP instance */
00322    int (*destroy)(struct ast_rtp_instance *instance);
00323    /*! Callback for writing out a frame */
00324    int (*write)(struct ast_rtp_instance *instance, struct ast_frame *frame);
00325    /*! Callback for stopping the RTP instance */
00326    void (*stop)(struct ast_rtp_instance *instance);
          .......
};

 

 

Ast_rtp_glue describes the data content bound between the RTP instance and the specific channel, the interface definition between the kernel and the RTP use module, and the peripheral modules of RTP need to implement related interfaces by themselves:

00396 /*! Structure that represents the glue that binds an RTP instance to a channel */
00397 struct ast_rtp_glue {
00398    /*! Name of the channel driver that this glue is responsible for */
00399    const char *type;
00400    /*! Module that the RTP glue came from */
00401    struct ast_module *mod;
00402    /*!
00403     * \brief Callback for retrieving the RTP instance carrying audio
00404     * \note This function increases the reference count on the returned RTP instance.
00405     */
00406    enum ast_rtp_glue_result (*get_rtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance);
00407    /*!
00408     * \brief Callback for retrieving the RTP instance carrying video
00409     * \note This function increases the reference count on the returned RTP instance.
00410     */
00411    enum ast_rtp_glue_result (*get_vrtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance);
00412    /*!
00413     * \brief Callback for retrieving the RTP instance carrying text
00414     * \note This function increases the reference count on the returned RTP instance.
00415     */
00416    enum ast_rtp_glue_result (*get_trtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance);
00417    /*! Callback for updating the destination that the remote side should send RTP to */
00418    int (*update_peer)(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, const struct ast_format_cap *cap, int nat_active);
00419    /*! Callback for retrieving codecs that the channel can do.  Result returned in result_cap*/
00420    void (*get_codec)(struct ast_channel *chan, struct ast_format_cap *result_cap);
00421    /*! Linked list information */
00422    AST_RWLIST_ENTRY(ast_rtp_glue) entry;
00423 };

 

 

The kernel defines two linked lists to manage rtpengine and RTP glue.

00080 /*! List of RTP engines that are currently registered */
00081 static AST_RWLIST_HEAD_STATIC(engines, ast_rtp_engine);
00082 
00083 /*! List of RTP glues */
00084 static AST_RWLIST_HEAD_STATIC(glues, ast_rtp_glue);

 

The kernel provides an abstract management and calling interface. The specific RTP application module interacts with the kernel API. The kernel then interacts with the FTP stack through the interface defined in ast_rtp_engine, to introduce a new RTP stack, we need to implement an engine module between the stack and the kernel to encapsulate these interfaces. In version 1.8, asterisk implements two engine modules: res_rtp_asterisk and res_rtp_multicast.

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.