2 * Asterisk -- A telephony toolkit for Linux.
4 * Real-time Transport Protocol support
6 * Copyright (C) 1999-2005, Digium
8 * Mark Spencer <markster@digium.com>
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License
14 #ifndef _ASTERISK_RTP_H
15 #define _ASTERISK_RTP_H
17 #include <asterisk/frame.h>
18 #include <asterisk/io.h>
19 #include <asterisk/sched.h>
20 #include <asterisk/channel.h>
22 #include <netinet/in.h>
24 #if defined(__cplusplus) || defined(c_plusplus)
28 /* Codes for RTP-specific data - not defined by our AST_FORMAT codes */
30 #define AST_RTP_DTMF (1 << 0)
31 /*! 'Comfort Noise' (RFC3389) */
32 #define AST_RTP_CN (1 << 1)
33 /*! DTMF (Cisco Proprietary) */
34 #define AST_RTP_CISCO_DTMF (1 << 2)
35 /*! Maximum RTP-specific code */
36 #define AST_RTP_MAX AST_RTP_CISCO_DTMF
38 struct ast_rtp_protocol {
39 /* Get RTP struct, or NULL if unwilling to transfer */
40 struct ast_rtp *(* const get_rtp_info)(struct ast_channel *chan);
41 /* Get RTP struct, or NULL if unwilling to transfer */
42 struct ast_rtp *(* const get_vrtp_info)(struct ast_channel *chan);
44 int (* const set_rtp_peer)(struct ast_channel *chan, struct ast_rtp *peer, struct ast_rtp *vpeer, int codecs);
45 int (* const get_codec)(struct ast_channel *chan);
46 const char * const type;
47 struct ast_rtp_protocol *next;
52 typedef int (*ast_rtp_callback)(struct ast_rtp *rtp, struct ast_frame *f, void *data);
54 struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode);
56 struct ast_rtp *ast_rtp_new_with_bindaddr(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode, struct in_addr in);
58 void ast_rtp_set_peer(struct ast_rtp *rtp, struct sockaddr_in *them);
60 void ast_rtp_get_peer(struct ast_rtp *rtp, struct sockaddr_in *them);
62 void ast_rtp_get_us(struct ast_rtp *rtp, struct sockaddr_in *us);
64 void ast_rtp_destroy(struct ast_rtp *rtp);
66 void ast_rtp_reset(struct ast_rtp *rtp);
68 void ast_rtp_set_callback(struct ast_rtp *rtp, ast_rtp_callback callback);
70 void ast_rtp_set_data(struct ast_rtp *rtp, void *data);
72 int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *f);
74 struct ast_frame *ast_rtp_read(struct ast_rtp *rtp);
76 struct ast_frame *ast_rtcp_read(struct ast_rtp *rtp);
78 int ast_rtp_fd(struct ast_rtp *rtp);
80 int ast_rtcp_fd(struct ast_rtp *rtp);
82 int ast_rtp_senddigit(struct ast_rtp *rtp, char digit);
84 int ast_rtp_sendcng(struct ast_rtp *rtp, int level);
86 int ast_rtp_settos(struct ast_rtp *rtp, int tos);
88 /* Setting RTP payload types from lines in a SDP description: */
89 void ast_rtp_pt_clear(struct ast_rtp* rtp);
90 /* Set payload types to defaults */
91 void ast_rtp_pt_default(struct ast_rtp* rtp);
92 void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt);
93 void ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
94 char* mimeType, char* mimeSubtype);
96 /* Mapping between RTP payload format codes and Asterisk codes: */
97 struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt);
98 int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code);
99 void ast_rtp_offered_from_local(struct ast_rtp* rtp, int local);
101 void ast_rtp_get_current_formats(struct ast_rtp* rtp,
102 int* astFormats, int* nonAstFormats);
104 /* Mapping an Asterisk code into a MIME subtype (string): */
105 char* ast_rtp_lookup_mime_subtype(int isAstFormat, int code);
107 /* Build a string of MIME subtype names from a capability list */
108 char *ast_rtp_lookup_mime_multiple(char *buf, int size, const int capability, const int isAstFormat);
110 void ast_rtp_setnat(struct ast_rtp *rtp, int nat);
112 int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc);
114 int ast_rtp_proto_register(struct ast_rtp_protocol *proto);
116 void ast_rtp_proto_unregister(struct ast_rtp_protocol *proto);
118 void ast_rtp_stop(struct ast_rtp *rtp);
120 void ast_rtp_init(void);
122 void ast_rtp_reload(void);
124 #if defined(__cplusplus) || defined(c_plusplus)