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.
21 * \brief Supports RTP and RTCP with Symmetric RTP support for NAT traversal.
23 * RTP is defined in RFC 3550.
26 #ifndef _ASTERISK_RTP_H
27 #define _ASTERISK_RTP_H
29 #include <netinet/in.h>
31 #include "asterisk/frame.h"
32 #include "asterisk/io.h"
33 #include "asterisk/sched.h"
34 #include "asterisk/channel.h"
35 #include "asterisk/linkedlists.h"
37 #if defined(__cplusplus) || defined(c_plusplus)
41 /* Codes for RTP-specific data - not defined by our AST_FORMAT codes */
43 #define AST_RTP_DTMF (1 << 0)
44 /*! 'Comfort Noise' (RFC3389) */
45 #define AST_RTP_CN (1 << 1)
46 /*! DTMF (Cisco Proprietary) */
47 #define AST_RTP_CISCO_DTMF (1 << 2)
48 /*! Maximum RTP-specific code */
49 #define AST_RTP_MAX AST_RTP_CISCO_DTMF
51 struct ast_rtp_protocol {
52 /*! Get RTP struct, or NULL if unwilling to transfer */
53 struct ast_rtp *(* const get_rtp_info)(struct ast_channel *chan);
54 /*! Get RTP struct, or NULL if unwilling to transfer */
55 struct ast_rtp *(* const get_vrtp_info)(struct ast_channel *chan);
57 int (* const set_rtp_peer)(struct ast_channel *chan, struct ast_rtp *peer, struct ast_rtp *vpeer, int codecs, int nat_active);
58 int (* const get_codec)(struct ast_channel *chan);
59 const char * const type;
60 AST_LIST_ENTRY(ast_rtp_protocol) list;
64 * \brief Structure representing a RTP session.
66 * RTP session is defined on page 9 of RFC 3550: "An association among a set of participants communicating with RTP. A participant may be involved in multiple RTP sessions at the same time [...]"
71 typedef int (*ast_rtp_callback)(struct ast_rtp *rtp, struct ast_frame *f, void *data);
74 * \brief Initializate a RTP session.
80 * \returns A representation (structure) of an RTP session.
82 struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode);
85 * \brief Initializate a RTP session using an in_addr structure.
87 * This fuction gets called by ast_rtp_new().
94 * \returns A representation (structure) of an RTP session.
96 struct ast_rtp *ast_rtp_new_with_bindaddr(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode, struct in_addr in);
98 void ast_rtp_set_peer(struct ast_rtp *rtp, struct sockaddr_in *them);
100 /* Copies from rtp to them and returns 1 if there was a change or 0 if it was already the same */
101 int ast_rtp_get_peer(struct ast_rtp *rtp, struct sockaddr_in *them);
103 void ast_rtp_get_us(struct ast_rtp *rtp, struct sockaddr_in *us);
105 void ast_rtp_destroy(struct ast_rtp *rtp);
107 void ast_rtp_reset(struct ast_rtp *rtp);
109 void ast_rtp_stun_request(struct ast_rtp *rtp, struct sockaddr_in *suggestion, const char *username);
111 void ast_rtp_set_callback(struct ast_rtp *rtp, ast_rtp_callback callback);
113 void ast_rtp_set_data(struct ast_rtp *rtp, void *data);
115 int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *f);
117 struct ast_frame *ast_rtp_read(struct ast_rtp *rtp);
119 struct ast_frame *ast_rtcp_read(struct ast_rtp *rtp);
121 int ast_rtp_fd(struct ast_rtp *rtp);
123 int ast_rtcp_fd(struct ast_rtp *rtp);
125 int ast_rtp_senddigit(struct ast_rtp *rtp, char digit);
127 int ast_rtp_sendcng(struct ast_rtp *rtp, int level);
129 int ast_rtp_settos(struct ast_rtp *rtp, int tos);
131 /*! \brief Setting RTP payload types from lines in a SDP description: */
132 void ast_rtp_pt_clear(struct ast_rtp* rtp);
133 /*! \brief Set payload types to defaults */
134 void ast_rtp_pt_default(struct ast_rtp* rtp);
135 void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt);
136 void ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
137 char* mimeType, char* mimeSubtype);
139 /*! \brief Mapping between RTP payload format codes and Asterisk codes: */
140 struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt);
141 int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code);
143 void ast_rtp_get_current_formats(struct ast_rtp* rtp,
144 int* astFormats, int* nonAstFormats);
146 /*! \brief Mapping an Asterisk code into a MIME subtype (string): */
147 char* ast_rtp_lookup_mime_subtype(int isAstFormat, int code);
149 /*! \brief Build a string of MIME subtype names from a capability list */
150 char *ast_rtp_lookup_mime_multiple(char *buf, int size, const int capability, const int isAstFormat);
152 void ast_rtp_setnat(struct ast_rtp *rtp, int nat);
154 int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
156 int ast_rtp_proto_register(struct ast_rtp_protocol *proto);
158 void ast_rtp_proto_unregister(struct ast_rtp_protocol *proto);
160 int ast_rtp_make_compatible(struct ast_channel *dest, struct ast_channel *src, int media);
162 int ast_rtp_early_media(struct ast_channel *dest, struct ast_channel *src);
164 void ast_rtp_stop(struct ast_rtp *rtp);
166 void ast_rtp_init(void);
168 int ast_rtp_reload(void);
170 #if defined(__cplusplus) || defined(c_plusplus)
174 #endif /* _ASTERISK_RTP_H */