From 1.6.2 to 1.6.3:
-* Nothing, yet!
+* The usage of RTP inside of Asterisk has now become modularized. This means
+ the Asterisk RTP stack now exists as a loadable module, res_rtp_asterisk.
+ If you are not using autoload=yes in modules.conf you will need to ensure
+ it is set to load. If not, then any module which uses RTP (such as chan_sip)
+ will not be able to send or receive calls.
From 1.6.1 to 1.6.2:
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/causes.h"
-#include "asterisk/rtp.h"
+#include "asterisk/rtp_engine.h"
#include "asterisk/cdr.h"
#include "asterisk/manager.h"
#include "asterisk/privacy.h"
char *new_cid_num, *new_cid_name;
struct ast_channel *src;
- ast_rtp_make_compatible(c, in, single);
+ if (single) {
+ ast_rtp_instance_early_bridge_make_compatible(c, in);
+ }
if (ast_test_flag64(o, OPT_FORCECLID)) {
new_cid_num = ast_strdup(S_OR(in->macroexten, in->exten));
new_cid_name = NULL; /* XXX no name ? */
pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", numsubst);
/* Setup outgoing SDP to match incoming one */
- ast_rtp_make_compatible(tc, chan, !outgoing && !rest);
+ if (!outgoing && !rest) {
+ ast_rtp_instance_early_bridge_make_compatible(tc, chan);
+ }
/* Inherit specially named variables from parent channel */
ast_channel_inherit_variables(chan, tc);
#include "asterisk/pbx.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
-#include "asterisk/rtp.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/file.h"
#include "asterisk/pbx.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
-#include "asterisk/rtp.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/file.h"
#include "asterisk/pbx.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
-#include "asterisk/rtp.h"
+#include "asterisk/rtp_engine.h"
+#include "asterisk/stun.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/file.h"
char cid_name[80]; /*!< Caller ID name */
char exten[80]; /*!< Called extension */
struct ast_channel *owner; /*!< Master Channel */
- struct ast_rtp *rtp; /*!< RTP audio session */
- struct ast_rtp *vrtp; /*!< RTP video session */
+ struct ast_rtp_instance *rtp; /*!< RTP audio session */
+ struct ast_rtp_instance *vrtp; /*!< RTP video session */
int jointcapability; /*!< Supported capability at both ends (codecs ) */
int peercapability;
struct gtalk_pvt *next; /* Next entity */
static struct gtalk_pvt *gtalk_alloc(struct gtalk *client, const char *us, const char *them, const char *sid);
static char *gtalk_do_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
static char *gtalk_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
-/*----- RTP interface functions */
-static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp,
- struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active);
-static enum ast_rtp_get_result gtalk_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
-static int gtalk_get_codec(struct ast_channel *chan);
/*! \brief PBX interface structure for channel registration */
static const struct ast_channel_tech gtalk_tech = {
.requester = gtalk_request,
.send_digit_begin = gtalk_digit_begin,
.send_digit_end = gtalk_digit_end,
- .bridge = ast_rtp_bridge,
+ .bridge = ast_rtp_instance_bridge,
.call = gtalk_call,
.hangup = gtalk_hangup,
.answer = gtalk_answer,
static struct io_context *io; /*!< The IO context */
static struct in_addr __ourip;
-/*! \brief RTP driver interface */
-static struct ast_rtp_protocol gtalk_rtp = {
- type: "Gtalk",
- get_rtp_info: gtalk_get_rtp_peer,
- set_rtp_peer: gtalk_set_rtp_peer,
- get_codec: gtalk_get_codec,
-};
-
static struct ast_cli_entry gtalk_cli[] = {
AST_CLI_DEFINE(gtalk_do_reload, "Reload GoogleTalk configuration"),
AST_CLI_DEFINE(gtalk_show_channels, "Show GoogleTalk channels"),
iks_insert_node(dcodecs, payload_gsm);
res++;
}
- ast_rtp_lookup_code(p->rtp, 1, codec);
+
return res;
}
return res;
}
-static enum ast_rtp_get_result gtalk_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp)
+static enum ast_rtp_glue_result gtalk_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
{
struct gtalk_pvt *p = chan->tech_pvt;
- enum ast_rtp_get_result res = AST_RTP_GET_FAILED;
+ enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_FORBID;
if (!p)
return res;
ast_mutex_lock(&p->lock);
if (p->rtp){
- *rtp = p->rtp;
- res = AST_RTP_TRY_PARTIAL;
+ ao2_ref(p->rtp, +1);
+ *instance = p->rtp;
+ res = AST_RTP_GLUE_RESULT_LOCAL;
}
ast_mutex_unlock(&p->lock);
return p->peercapability;
}
-static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active)
+static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, int codecs, int nat_active)
{
struct gtalk_pvt *p;
return 0;
}
+static struct ast_rtp_glue gtalk_rtp_glue = {
+ .type = "Gtalk",
+ .get_rtp_info = gtalk_get_rtp_peer,
+ .get_codec = gtalk_get_codec,
+ .update_peer = gtalk_set_rtp_peer,
+};
+
static int gtalk_response(struct gtalk *client, char *from, ikspak *pak, const char *reasonstr, const char *reasonstr2)
{
iks *response = NULL, *error = NULL, *reason = NULL;
/* codec points to the first <payload-type/> tag */
codec = iks_first_tag(iks_first_tag(iks_first_tag(pak->x)));
while (codec) {
- ast_rtp_set_m_type(tmp->rtp, atoi(iks_find_attrib(codec, "id")));
- ast_rtp_set_rtpmap_type(tmp->rtp, atoi(iks_find_attrib(codec, "id")), "audio", iks_find_attrib(codec, "name"), 0);
+ ast_rtp_codecs_payloads_set_m_type(ast_rtp_instance_get_codecs(tmp->rtp), tmp->rtp, atoi(iks_find_attrib(codec, "id")));
+ ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(tmp->rtp), tmp->rtp, atoi(iks_find_attrib(codec, "id")), "audio", iks_find_attrib(codec, "name"), 0);
codec = iks_next_tag(codec);
}
/* Now gather all of the codecs that we are asked for */
- ast_rtp_get_current_formats(tmp->rtp, &tmp->peercapability, &peernoncodeccapability);
+ ast_rtp_codecs_payload_formats(ast_rtp_instance_get_codecs(tmp->rtp), &tmp->peercapability, &peernoncodeccapability);
/* at this point, we received an awser from the remote Gtalk client,
which allows us to compare capabilities */
goto safeout;
}
- ast_rtp_get_us(p->rtp, &sin);
+ ast_rtp_instance_get_local_address(p->rtp, &sin);
ast_find_ourip(&us, bindaddr);
if (!strcmp(ast_inet_ntoa(us), "127.0.0.1")) {
ast_log(LOG_WARNING, "Found a loopback IP on the system, check your network configuration or set the bindaddr attribute.");
tmp->initiator = 1;
}
/* clear codecs */
- tmp->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
- ast_rtp_pt_clear(tmp->rtp);
+ tmp->rtp = ast_rtp_instance_new(NULL, sched, &bindaddr, NULL);
+ ast_rtp_instance_set_prop(tmp->rtp, AST_RTP_PROPERTY_RTCP, 1);
+ ast_rtp_codecs_payloads_clear(ast_rtp_instance_get_codecs(tmp->rtp), tmp->rtp);
/* add user configured codec capabilites */
if (client->capability)
/* Set Frame packetization */
if (i->rtp)
- ast_rtp_codec_setpref(i->rtp, &i->prefs);
+ ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(i->rtp), i->rtp, &i->prefs);
tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
fmt = ast_best_codec(tmp->nativeformats);
if (i->rtp) {
- ast_rtp_setstun(i->rtp, 1);
- ast_channel_set_fd(tmp, 0, ast_rtp_fd(i->rtp));
- ast_channel_set_fd(tmp, 1, ast_rtcp_fd(i->rtp));
+ ast_rtp_instance_set_prop(i->rtp, AST_RTP_PROPERTY_STUN, 1);
+ ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(i->rtp, 0));
+ ast_channel_set_fd(tmp, 1, ast_rtp_instance_fd(i->rtp, 1));
}
if (i->vrtp) {
- ast_rtp_setstun(i->rtp, 1);
- ast_channel_set_fd(tmp, 2, ast_rtp_fd(i->vrtp));
- ast_channel_set_fd(tmp, 3, ast_rtcp_fd(i->vrtp));
+ ast_rtp_instance_set_prop(i->vrtp, AST_RTP_PROPERTY_STUN, 1);
+ ast_channel_set_fd(tmp, 2, ast_rtp_instance_fd(i->vrtp, 0));
+ ast_channel_set_fd(tmp, 3, ast_rtp_instance_fd(i->vrtp, 1));
}
if (state == AST_STATE_RING)
tmp->rings = 1;
if (p->owner)
ast_log(LOG_WARNING, "Uh oh, there's an owner, this is going to be messy.\n");
if (p->rtp)
- ast_rtp_destroy(p->rtp);
+ ast_rtp_instance_destroy(p->rtp);
if (p->vrtp)
- ast_rtp_destroy(p->vrtp);
+ ast_rtp_instance_destroy(p->vrtp);
gtalk_free_candidates(p->theircandidates);
ast_free(p);
}
codec = iks_first_tag(iks_first_tag(iks_first_tag(pak->x)));
while (codec) {
- ast_rtp_set_m_type(p->rtp, atoi(iks_find_attrib(codec, "id")));
- ast_rtp_set_rtpmap_type(p->rtp, atoi(iks_find_attrib(codec, "id")), "audio", iks_find_attrib(codec, "name"), 0);
+ ast_rtp_codecs_payloads_set_m_type(ast_rtp_instance_get_codecs(p->rtp), p->rtp, atoi(iks_find_attrib(codec, "id")));
+ ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp), p->rtp, atoi(iks_find_attrib(codec, "id")), "audio", iks_find_attrib(codec, "name"), 0);
codec = iks_next_tag(codec);
}
/* Now gather all of the codecs that we are asked for */
- ast_rtp_get_current_formats(p->rtp, &p->peercapability, &peernoncodeccapability);
+ ast_rtp_codecs_payload_formats(ast_rtp_instance_get_codecs(p->rtp), &p->peercapability, &peernoncodeccapability);
p->jointcapability = p->capability & p->peercapability;
ast_mutex_unlock(&p->lock);
p->ourcandidates->username);
/* Find out the result of the STUN */
- ast_rtp_get_peer(p->rtp, &aux);
+ ast_rtp_instance_get_remote_address(p->rtp, &aux);
/* If the STUN result is different from the IP of the hostname,
lock on the stun IP of the hostname advertised by the
remote client */
if (aux.sin_addr.s_addr &&
aux.sin_addr.s_addr != sin.sin_addr.s_addr)
- ast_rtp_stun_request(p->rtp, &aux, username);
+ ast_rtp_instance_stun_request(p->rtp, &aux, username);
else
- ast_rtp_stun_request(p->rtp, &sin, username);
+ ast_rtp_instance_stun_request(p->rtp, &sin, username);
if (aux.sin_addr.s_addr) {
ast_debug(4, "Receiving RTP traffic from IP %s, matches with remote candidate's IP %s\n", ast_inet_ntoa(aux.sin_addr), tmp->ip);
if (!p->rtp)
return &ast_null_frame;
- f = ast_rtp_read(p->rtp);
+ f = ast_rtp_instance_read(p->rtp, 0);
gtalk_update_stun(p->parent, p);
if (p->owner) {
/* We already hold the channel lock */
if (p) {
ast_mutex_lock(&p->lock);
if (p->rtp) {
- res = ast_rtp_write(p->rtp, frame);
+ res = ast_rtp_instance_write(p->rtp, frame);
}
ast_mutex_unlock(&p->lock);
}
if (p) {
ast_mutex_lock(&p->lock);
if (p->vrtp) {
- res = ast_rtp_write(p->vrtp, frame);
+ res = ast_rtp_instance_write(p->vrtp, frame);
}
ast_mutex_unlock(&p->lock);
}
return 0;
}
- ast_rtp_proto_register(>alk_rtp);
+ ast_rtp_glue_register(>alk_rtp_glue);
ast_cli_register_multiple(gtalk_cli, ARRAY_LEN(gtalk_cli));
/* Make sure we can register our channel type */
ast_cli_unregister_multiple(gtalk_cli, ARRAY_LEN(gtalk_cli));
/* First, take us out of the channel loop */
ast_channel_unregister(>alk_tech);
- ast_rtp_proto_unregister(>alk_rtp);
+ ast_rtp_glue_unregister(>alk_rtp_glue);
if (!ast_mutex_lock(>alklock)) {
/* Hangup all interfaces if they have an owner */
#include "asterisk/utils.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
-#include "asterisk/rtp.h"
+#include "asterisk/rtp_engine.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/cli.h"
char accountcode[256]; /*!< Account code */
char rdnis[80]; /*!< Referring DNIS, if available */
int amaflags; /*!< AMA Flags */
- struct ast_rtp *rtp; /*!< RTP Session */
+ struct ast_rtp_instance *rtp; /*!< RTP Session */
struct ast_dsp *vad; /*!< Used for in-band DTMF detection */
int nativeformats; /*!< Codec formats supported by a channel */
int needhangup; /*!< Send hangup when Asterisk is ready */
.write = oh323_write,
.indicate = oh323_indicate,
.fixup = oh323_fixup,
- .bridge = ast_rtp_bridge,
+ .bridge = ast_rtp_instance_bridge,
};
static const char* redirectingreason2str(int redirectingreason)
if (pvt->update_rtp_info > 0) {
if (pvt->rtp) {
ast_jb_configure(c, &global_jbconf);
- ast_channel_set_fd(c, 0, ast_rtp_fd(pvt->rtp));
- ast_channel_set_fd(c, 1, ast_rtcp_fd(pvt->rtp));
+ ast_channel_set_fd(c, 0, ast_rtp_instance_fd(pvt->rtp, 0));
+ ast_channel_set_fd(c, 1, ast_rtp_instance_fd(pvt->rtp, 1));
ast_queue_frame(pvt->owner, &ast_null_frame); /* Tell Asterisk to apply changes */
}
pvt->update_rtp_info = -1;
AST_SCHED_DEL(sched, pvt->DTMFsched);
if (pvt->rtp) {
- ast_rtp_destroy(pvt->rtp);
+ ast_rtp_instance_destroy(pvt->rtp);
}
/* Free dsp used for in-band DTMF detection */
if (h323debug) {
ast_log(LOG_DTMF, "Begin sending out-of-band digit %c on %s\n", digit, c->name);
}
- ast_rtp_senddigit_begin(pvt->rtp, digit);
+ ast_rtp_instance_dtmf_begin(pvt->rtp, digit);
ast_mutex_unlock(&pvt->lock);
} else if (pvt->txDtmfDigit != digit) {
/* in-band DTMF */
if (h323debug) {
ast_log(LOG_DTMF, "End sending out-of-band digit %c on %s, duration %d\n", digit, c->name, duration);
}
- ast_rtp_senddigit_end(pvt->rtp, digit);
+ ast_rtp_instance_dtmf_end(pvt->rtp, digit);
ast_mutex_unlock(&pvt->lock);
} else {
/* in-band DTMF */
/* Only apply it for the first packet, we just need the correct ip/port */
if (pvt->options.nat) {
- ast_rtp_setnat(pvt->rtp, pvt->options.nat);
+ ast_rtp_instance_set_prop(pvt->rtp, AST_RTP_PROPERTY_NAT, pvt->options.nat);
pvt->options.nat = 0;
}
- f = ast_rtp_read(pvt->rtp);
+ f = ast_rtp_instance_read(pvt->rtp, 0);
/* Don't send RFC2833 if we're not supposed to */
if (f && (f->frametype == AST_FRAME_DTMF) && !(pvt->options.dtmfmode & (H323_DTMF_RFC2833 | H323_DTMF_CISCO))) {
return &ast_null_frame;
break;
case 1:
if (pvt->rtp)
- fr = ast_rtcp_read(pvt->rtp);
+ fr = ast_rtp_instance_read(pvt->rtp, 1);
else
fr = &ast_null_frame;
break;
if (pvt) {
ast_mutex_lock(&pvt->lock);
if (pvt->rtp && !pvt->recvonly)
- res = ast_rtp_write(pvt->rtp, frame);
+ res = ast_rtp_instance_write(pvt->rtp, frame);
__oh323_update_info(c, pvt);
ast_mutex_unlock(&pvt->lock);
}
res = 0;
break;
case AST_CONTROL_SRCUPDATE:
- ast_rtp_new_source(pvt->rtp);
+ ast_rtp_instance_new_source(pvt->rtp);
res = 0;
break;
case AST_CONTROL_PROCEEDING:
static int __oh323_rtp_create(struct oh323_pvt *pvt)
{
- struct in_addr our_addr;
+ struct sockaddr_in our_addr;
if (pvt->rtp)
return 0;
- if (ast_find_ourip(&our_addr, bindaddr)) {
+ if (ast_find_ourip(&our_addr.sin_addr, bindaddr)) {
ast_mutex_unlock(&pvt->lock);
ast_log(LOG_ERROR, "Unable to locate local IP address for RTP stream\n");
return -1;
}
- pvt->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, our_addr);
+ pvt->rtp = ast_rtp_instance_new(NULL, sched, &our_addr, NULL);
if (!pvt->rtp) {
ast_mutex_unlock(&pvt->lock);
ast_log(LOG_WARNING, "Unable to create RTP session: %s\n", strerror(errno));
if (h323debug)
ast_debug(1, "Created RTP channel\n");
- ast_rtp_setqos(pvt->rtp, tos, cos, "H323 RTP");
+ ast_rtp_instance_set_qos(pvt->rtp, tos, cos, "H323 RTP");
if (h323debug)
ast_debug(1, "Setting NAT on RTP to %d\n", pvt->options.nat);
- ast_rtp_setnat(pvt->rtp, pvt->options.nat);
+ ast_rtp_instance_set_prop(pvt->rtp, AST_RTP_PROPERTY_NAT, pvt->options.nat);
if (pvt->dtmf_pt[0] > 0)
- ast_rtp_set_rtpmap_type(pvt->rtp, pvt->dtmf_pt[0], "audio", "telephone-event", 0);
+ ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, pvt->dtmf_pt[0], "audio", "telephone-event", 0);
if (pvt->dtmf_pt[1] > 0)
- ast_rtp_set_rtpmap_type(pvt->rtp, pvt->dtmf_pt[1], "audio", "cisco-telephone-event", 0);
+ ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, pvt->dtmf_pt[1], "audio", "cisco-telephone-event", 0);
if (pvt->peercapability)
- ast_rtp_codec_setpref(pvt->rtp, &pvt->peer_prefs);
+ ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, &pvt->peer_prefs);
if (pvt->owner && !ast_channel_trylock(pvt->owner)) {
ast_jb_configure(pvt->owner, &global_jbconf);
- ast_channel_set_fd(pvt->owner, 0, ast_rtp_fd(pvt->rtp));
- ast_channel_set_fd(pvt->owner, 1, ast_rtcp_fd(pvt->rtp));
+ ast_channel_set_fd(pvt->owner, 0, ast_rtp_instance_fd(pvt->rtp, 0));
+ ast_channel_set_fd(pvt->owner, 1, ast_rtp_instance_fd(pvt->rtp, 1));
ast_queue_frame(pvt->owner, &ast_null_frame); /* Tell Asterisk to apply changes */
ast_channel_unlock(pvt->owner);
} else
if (!pvt->rtp)
__oh323_rtp_create(pvt);
#if 0
- ast_channel_set_fd(ch, 0, ast_rtp_fd(pvt->rtp));
- ast_channel_set_fd(ch, 1, ast_rtcp_fd(pvt->rtp));
+ ast_channel_set_fd(ch, 0, ast_rtp_instance_fd(pvt->rtp, 0));
+ ast_channel_set_fd(ch, 1, ast_rtp_instance_fd(pvt->rtp, 1));
#endif
#ifdef VIDEO_SUPPORT
if (pvt->vrtp) {
- ast_channel_set_fd(ch, 2, ast_rtp_fd(pvt->vrtp));
- ast_channel_set_fd(ch, 3, ast_rtcp_fd(pvt->vrtp));
+ ast_channel_set_fd(ch, 2, ast_rtp_instance_fd(pvt->vrtp, 0));
+ ast_channel_set_fd(ch, 3, ast_rtp_instance_fd(pvt->vrtp, 1));
}
#endif
#ifdef T38_SUPPORT
}
if (!pvt->cd.call_token) {
ast_log(LOG_ERROR, "Not enough memory to alocate call token\n");
- ast_rtp_destroy(pvt->rtp);
+ ast_rtp_instance_destroy(pvt->rtp);
ast_free(pvt);
return NULL;
}
return NULL;
}
/* figure out our local RTP port and tell the H.323 stack about it */
- ast_rtp_get_us(pvt->rtp, &us);
+ ast_rtp_instance_get_local_address(pvt->rtp, &us);
ast_mutex_unlock(&pvt->lock);
ast_copy_string(info->addr, ast_inet_ntoa(us.sin_addr), sizeof(info->addr));
{
struct oh323_pvt *pvt;
struct sockaddr_in them;
- struct rtpPayloadType rtptype;
int nativeformats_changed;
enum { NEED_NONE, NEED_HOLD, NEED_UNHOLD } rtp_change = NEED_NONE;
__oh323_rtp_create(pvt);
if ((pt == 2) && (pvt->jointcapability & AST_FORMAT_G726_AAL2)) {
- ast_rtp_set_rtpmap_type(pvt->rtp, pt, "audio", "G726-32", AST_RTP_OPT_G726_NONSTANDARD);
+ ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, pt, "audio", "G726-32", AST_RTP_OPT_G726_NONSTANDARD);
}
them.sin_family = AF_INET;
them.sin_port = htons(remotePort);
if (them.sin_addr.s_addr) {
- ast_rtp_set_peer(pvt->rtp, &them);
+ ast_rtp_instance_set_remote_address(pvt->rtp, &them);
if (pvt->recvonly) {
pvt->recvonly = 0;
rtp_change = NEED_UNHOLD;
}
} else {
- ast_rtp_stop(pvt->rtp);
+ ast_rtp_instance_stop(pvt->rtp);
if (!pvt->recvonly) {
pvt->recvonly = 1;
rtp_change = NEED_HOLD;
/* Change native format to reflect information taken from OLC/OLCAck */
nativeformats_changed = 0;
if (pt != 128 && pvt->rtp) { /* Payload type is invalid, so try to use previously decided */
- rtptype = ast_rtp_lookup_pt(pvt->rtp, pt);
+ struct ast_rtp_payload_type rtptype = ast_rtp_codecs_payload_lookup(ast_rtp_instance_get_codecs(pvt->rtp), pt);
if (h323debug)
ast_debug(1, "Native format is set to %d from %d by RTP payload type %d\n", rtptype.code, pvt->nativeformats, pt);
if (pvt->nativeformats != rtptype.code) {
}
if (pvt->rtp) {
/* Immediately stop RTP */
- ast_rtp_destroy(pvt->rtp);
+ ast_rtp_instance_destroy(pvt->rtp);
pvt->rtp = NULL;
}
/* Free dsp used for in-band DTMF detection */
return;
}
if (pvt->rtp) {
- ast_rtp_set_rtpmap_type(pvt->rtp, payload, "audio", (is_cisco ? "cisco-telephone-event" : "telephone-event"), 0);
+ ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, payload, "audio", (is_cisco ? "cisco-telephone-event" : "telephone-event"), 0);
}
pvt->dtmf_pt[is_cisco ? 1 : 0] = payload;
ast_mutex_unlock(&pvt->lock);
}
}
if (pvt->rtp)
- ast_rtp_codec_setpref(pvt->rtp, &pvt->peer_prefs);
+ ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, &pvt->peer_prefs);
}
ast_mutex_unlock(&pvt->lock);
}
static struct ast_cli_entry cli_h323_reload =
AST_CLI_DEFINE(handle_cli_h323_reload, "Reload H.323 configuration");
-static enum ast_rtp_get_result oh323_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp)
+static enum ast_rtp_glue_result oh323_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
{
struct oh323_pvt *pvt;
- enum ast_rtp_get_result res = AST_RTP_TRY_PARTIAL;
+ enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_LOCAL;
if (!(pvt = (struct oh323_pvt *)chan->tech_pvt))
- return AST_RTP_GET_FAILED;
+ return AST_RTP_GLUE_RESULT_FORBID;
ast_mutex_lock(&pvt->lock);
- *rtp = pvt->rtp;
+ *instance = pvt->rtp ? ao2_ref(pvt->rtp, +1), pvt->rtp : NULL;
#if 0
if (pvt->options.bridge) {
- res = AST_RTP_TRY_NATIVE;
+ res = AST_RTP_GLUE_RESULT_REMOTE;
}
#endif
ast_mutex_unlock(&pvt->lock);
return res;
}
-static enum ast_rtp_get_result oh323_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp **rtp)
-{
- return AST_RTP_GET_FAILED;
-}
-
static char *convertcap(int cap)
{
switch (cap) {
}
}
-static int oh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active)
+static int oh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, int codecs, int nat_active)
{
/* XXX Deal with Video */
struct oh323_pvt *pvt;
ast_log(LOG_ERROR, "No Private Structure, this is bad\n");
return -1;
}
- ast_rtp_get_peer(rtp, &them);
- ast_rtp_get_us(rtp, &us);
+ ast_rtp_instance_get_remote_address(rtp, &them);
+ ast_rtp_instance_get_local_address(rtp, &us);
#if 0 /* Native bridge still isn't ready */
h323_native_bridge(pvt->cd.call_token, ast_inet_ntoa(them.sin_addr), mode);
#endif
return 0;
}
-static struct ast_rtp_protocol oh323_rtp = {
+static struct ast_rtp_glue oh323_rtp_glue = {
.type = "H323",
.get_rtp_info = oh323_get_rtp_peer,
- .get_vrtp_info = oh323_get_vrtp_peer,
- .set_rtp_peer = oh323_set_rtp_peer,
+ .update_peer = oh323_set_rtp_peer,
};
static enum ast_module_load_result load_module(void)
}
ast_cli_register_multiple(cli_h323, sizeof(cli_h323) / sizeof(struct ast_cli_entry));
- ast_rtp_proto_register(&oh323_rtp);
+ ast_rtp_glue_register(&oh323_rtp_glue);
/* Register our callback functions */
h323_callback_register(setup_incoming_call,
/* start the h.323 listener */
if (h323_start_listener(h323_signalling_port, bindaddr)) {
ast_log(LOG_ERROR, "Unable to create H323 listener.\n");
- ast_rtp_proto_unregister(&oh323_rtp);
+ ast_rtp_glue_unregister(&oh323_rtp_glue);
ast_cli_unregister_multiple(cli_h323, sizeof(cli_h323) / sizeof(struct ast_cli_entry));
ast_cli_unregister(&cli_h323_reload);
h323_end_process();
ast_cli_unregister(&cli_h323_reload);
ast_channel_unregister(&oh323_tech);
- ast_rtp_proto_unregister(&oh323_rtp);
+ ast_rtp_glue_unregister(&oh323_rtp_glue);
if (!ast_mutex_lock(&iflock)) {
/* hangup all interfaces if they have an owner */
#include "asterisk/pbx.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
-#include "asterisk/rtp.h"
+#include "asterisk/rtp_engine.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/file.h"
char exten[80]; /*!< Called extension */
struct ast_channel *owner; /*!< Master Channel */
char audio_content_name[100]; /*!< name attribute of content tag */
- struct ast_rtp *rtp; /*!< RTP audio session */
+ struct ast_rtp_instance *rtp; /*!< RTP audio session */
char video_content_name[100]; /*!< name attribute of content tag */
- struct ast_rtp *vrtp; /*!< RTP video session */
+ struct ast_rtp_instance *vrtp; /*!< RTP video session */
int jointcapability; /*!< Supported capability at both ends (codecs ) */
int peercapability;
struct jingle_pvt *next; /* Next entity */
static struct jingle_pvt *jingle_alloc(struct jingle *client, const char *from, const char *sid);
static char *jingle_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
static char *jingle_do_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
-/*----- RTP interface functions */
-static int jingle_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp,
- struct ast_rtp *vrtp, struct ast_rtp *tpeer, int codecs, int nat_active);
-static enum ast_rtp_get_result jingle_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
-static int jingle_get_codec(struct ast_channel *chan);
/*! \brief PBX interface structure for channel registration */
static const struct ast_channel_tech jingle_tech = {
.requester = jingle_request,
.send_digit_begin = jingle_digit_begin,
.send_digit_end = jingle_digit_end,
- .bridge = ast_rtp_bridge,
+ .bridge = ast_rtp_instance_bridge,
.call = jingle_call,
.hangup = jingle_hangup,
.answer = jingle_answer,
static struct io_context *io; /*!< The IO context */
static struct in_addr __ourip;
-
-/*! \brief RTP driver interface */
-static struct ast_rtp_protocol jingle_rtp = {
- type: "Jingle",
- get_rtp_info: jingle_get_rtp_peer,
- set_rtp_peer: jingle_set_rtp_peer,
- get_codec: jingle_get_codec,
-};
-
static struct ast_cli_entry jingle_cli[] = {
AST_CLI_DEFINE(jingle_do_reload, "Reload Jingle configuration"),
AST_CLI_DEFINE(jingle_show_channels, "Show Jingle channels"),
iks_insert_attrib(payload_g723, "name", "G723");
iks_insert_node(dcodecs, payload_g723);
}
- ast_rtp_lookup_code(p->rtp, 1, codec);
}
static int jingle_accept_call(struct jingle *client, struct jingle_pvt *p)
return res;
}
-static enum ast_rtp_get_result jingle_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp)
+static enum ast_rtp_glue_result jingle_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
{
struct jingle_pvt *p = chan->tech_pvt;
- enum ast_rtp_get_result res = AST_RTP_GET_FAILED;
+ enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_FORBID;
if (!p)
return res;
ast_mutex_lock(&p->lock);
if (p->rtp) {
- *rtp = p->rtp;
- res = AST_RTP_TRY_PARTIAL;
+ ao2_ref(p->rtp, +1);
+ *instance = p->rtp;
+ res = AST_RTP_GLUE_RESULT_LOCAL;
}
ast_mutex_unlock(&p->lock);
return p->peercapability;
}
-static int jingle_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *tpeer, int codecs, int nat_active)
+static int jingle_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *tpeer, int codecs, int nat_active)
{
struct jingle_pvt *p;
return 0;
}
+static struct ast_rtp_glue jingle_rtp_glue = {
+ .type = "Jingle",
+ .get_rtp_info = jingle_get_rtp_peer,
+ .get_codec = jingle_get_codec,
+ .update_peer = jingle_set_rtp_peer,
+};
+
static int jingle_response(struct jingle *client, ikspak *pak, const char *reasonstr, const char *reasonstr2)
{
iks *response = NULL, *error = NULL, *reason = NULL;
goto safeout;
}
- ast_rtp_get_us(p->rtp, &sin);
+ ast_rtp_instance_get_local_address(p->rtp, &sin);
ast_find_ourip(&us, bindaddr);
/* Setup our first jingle candidate */
ast_copy_string(tmp->them, idroster, sizeof(tmp->them));
tmp->initiator = 1;
}
- tmp->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
+ tmp->rtp = ast_rtp_instance_new(NULL, sched, &bindaddr, NULL);
tmp->parent = client;
if (!tmp->rtp) {
ast_log(LOG_WARNING, "Out of RTP sessions?\n");
/* Set Frame packetization */
if (i->rtp)
- ast_rtp_codec_setpref(i->rtp, &i->prefs);
+ ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(i->rtp), i->rtp, &i->prefs);
tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
fmt = ast_best_codec(tmp->nativeformats);
if (i->rtp) {
- ast_channel_set_fd(tmp, 0, ast_rtp_fd(i->rtp));
- ast_channel_set_fd(tmp, 1, ast_rtcp_fd(i->rtp));
+ ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(i->rtp, 0));
+ ast_channel_set_fd(tmp, 1, ast_rtp_instance_fd(i->rtp, 1));
}
if (i->vrtp) {
- ast_channel_set_fd(tmp, 2, ast_rtp_fd(i->vrtp));
- ast_channel_set_fd(tmp, 3, ast_rtcp_fd(i->vrtp));
+ ast_channel_set_fd(tmp, 2, ast_rtp_instance_fd(i->vrtp, 0));
+ ast_channel_set_fd(tmp, 3, ast_rtp_instance_fd(i->vrtp, 1));
}
if (state == AST_STATE_RING)
tmp->rings = 1;
if (p->owner)
ast_log(LOG_WARNING, "Uh oh, there's an owner, this is going to be messy.\n");
if (p->rtp)
- ast_rtp_destroy(p->rtp);
+ ast_rtp_instance_destroy(p->rtp);
if (p->vrtp)
- ast_rtp_destroy(p->vrtp);
+ ast_rtp_instance_destroy(p->vrtp);
jingle_free_candidates(p->theircandidates);
ast_free(p);
}
ast_copy_string(p->audio_content_name, iks_find_attrib(content, "name"), sizeof(p->audio_content_name));
while (codec) {
- ast_rtp_set_m_type(p->rtp, atoi(iks_find_attrib(codec, "id")));
- ast_rtp_set_rtpmap_type(p->rtp, atoi(iks_find_attrib(codec, "id")), "audio", iks_find_attrib(codec, "name"), 0);
+ ast_rtp_codecs_payloads_set_m_type(ast_rtp_instance_get_codecs(p->rtp), p->rtp, atoi(iks_find_attrib(codec, "id")));
+ ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp), p->rtp, atoi(iks_find_attrib(codec, "id")), "audio", iks_find_attrib(codec, "name"), 0);
codec = iks_next(codec);
}
}
ast_copy_string(p->video_content_name, iks_find_attrib(content, "name"), sizeof(p->video_content_name));
while (codec) {
- ast_rtp_set_m_type(p->rtp, atoi(iks_find_attrib(codec, "id")));
- ast_rtp_set_rtpmap_type(p->rtp, atoi(iks_find_attrib(codec, "id")), "audio", iks_find_attrib(codec, "name"), 0);
+ ast_rtp_codecs_payloads_set_m_type(ast_rtp_instance_get_codecs(p->rtp), p->rtp, atoi(iks_find_attrib(codec, "id")));
+ ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp), p->rtp, atoi(iks_find_attrib(codec, "id")), "audio", iks_find_attrib(codec, "name"), 0);
codec = iks_next(codec);
}
}
sin.sin_port = htons(tmp->port);
snprintf(username, sizeof(username), "%s:%s", tmp->ufrag, p->ourcandidates->ufrag);
- ast_rtp_stun_request(p->rtp, &sin, username);
+ ast_rtp_instance_stun_request(p->rtp, &sin, username);
tmp = tmp->next;
}
return 1;
if (!p->rtp)
return &ast_null_frame;
- f = ast_rtp_read(p->rtp);
+ f = ast_rtp_instance_read(p->rtp, 0);
jingle_update_stun(p->parent, p);
if (p->owner) {
/* We already hold the channel lock */
if (p) {
ast_mutex_lock(&p->lock);
if (p->rtp) {
- res = ast_rtp_write(p->rtp, frame);
+ res = ast_rtp_instance_write(p->rtp, frame);
}
ast_mutex_unlock(&p->lock);
}
if (p) {
ast_mutex_lock(&p->lock);
if (p->vrtp) {
- res = ast_rtp_write(p->vrtp, frame);
+ res = ast_rtp_instance_write(p->vrtp, frame);
}
ast_mutex_unlock(&p->lock);
}
return 0;
}
- ast_rtp_proto_register(&jingle_rtp);
+ ast_rtp_glue_register(&jingle_rtp_glue);
ast_cli_register_multiple(jingle_cli, ARRAY_LEN(jingle_cli));
/* Make sure we can register our channel type */
if (ast_channel_register(&jingle_tech)) {
ast_cli_unregister_multiple(jingle_cli, ARRAY_LEN(jingle_cli));
/* First, take us out of the channel loop */
ast_channel_unregister(&jingle_tech);
- ast_rtp_proto_unregister(&jingle_rtp);
+ ast_rtp_glue_unregister(&jingle_rtp_glue);
if (!ast_mutex_lock(&jinglelock)) {
/* Hangup all interfaces if they have an owner */
#include "asterisk/pbx.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
-#include "asterisk/rtp.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/file.h"
#include "asterisk/pbx.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
-#include "asterisk/rtp.h"
+#include "asterisk/rtp_engine.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/cli.h"
int id;
struct ast_channel *owner;
struct mgcp_endpoint *parent;
- struct ast_rtp *rtp;
+ struct ast_rtp_instance *rtp;
struct sockaddr_in tmpdest;
char txident[80]; /*! \todo FIXME txident is replaced by rqnt_ident in endpoint.
This should be obsoleted */
static int transmit_notify_request(struct mgcp_subchannel *sub, char *tone);
static int transmit_modify_request(struct mgcp_subchannel *sub);
static int transmit_notify_request_with_callerid(struct mgcp_subchannel *sub, char *tone, char *callernum, char *callername);
-static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp *rtp, int codecs);
+static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp_instance *rtp, int codecs);
static int transmit_connection_del(struct mgcp_subchannel *sub);
static int transmit_audit_endpoint(struct mgcp_endpoint *p);
static void start_rtp(struct mgcp_subchannel *sub);
.fixup = mgcp_fixup,
.send_digit_begin = mgcp_senddigit_begin,
.send_digit_end = mgcp_senddigit_end,
- .bridge = ast_rtp_bridge,
+ .bridge = ast_rtp_instance_bridge,
};
static void mwi_event_cb(const struct ast_event *event, void *userdata)
sub->alreadygone = 0;
memset(&sub->tmpdest, 0, sizeof(sub->tmpdest));
if (sub->rtp) {
- ast_rtp_destroy(sub->rtp);
+ ast_rtp_instance_destroy(sub->rtp);
sub->rtp = NULL;
}
dump_cmd_queues(NULL, sub); /* SC */
/* Reset temporary destination */
memset(&sub->tmpdest, 0, sizeof(sub->tmpdest));
if (sub->rtp) {
- ast_rtp_destroy(sub->rtp);
+ ast_rtp_instance_destroy(sub->rtp);
sub->rtp = NULL;
}
/* Retrieve audio/etc from channel. Assumes sub->lock is already held. */
struct ast_frame *f;
- f = ast_rtp_read(sub->rtp);
+ f = ast_rtp_instance_read(sub->rtp, 0);
/* Don't send RFC2833 if we're not supposed to */
if (f && (f->frametype == AST_FRAME_DTMF) && !(sub->parent->dtmfmode & MGCP_DTMF_RFC2833))
return &ast_null_frame;
ast_mutex_lock(&sub->lock);
if ((sub->parent->sub == sub) || !sub->parent->singlepath) {
if (sub->rtp) {
- res = ast_rtp_write(sub->rtp, frame);
+ res = ast_rtp_instance_write(sub->rtp, frame);
}
}
ast_mutex_unlock(&sub->lock);
res = -1; /* Let asterisk play inband indications */
} else if (p->dtmfmode & MGCP_DTMF_RFC2833) {
ast_log(LOG_DEBUG, "Sending DTMF using RFC2833");
- ast_rtp_senddigit_begin(sub->rtp, digit);
+ ast_rtp_instance_dtmf_begin(sub->rtp, digit);
} else {
ast_log(LOG_ERROR, "Don't know about DTMF_MODE %d\n", p->dtmfmode);
}
tmp[2] = digit;
tmp[3] = '\0';
transmit_notify_request(sub, tmp);
- ast_rtp_senddigit_end(sub->rtp, digit);
+ ast_rtp_instance_dtmf_end(sub->rtp, digit);
} else {
ast_log(LOG_ERROR, "Don't know about DTMF_MODE %d\n", p->dtmfmode);
}
ast_moh_stop(ast);
break;
case AST_CONTROL_SRCUPDATE:
- ast_rtp_new_source(sub->rtp);
+ ast_rtp_instance_new_source(sub->rtp);
break;
case -1:
transmit_notify_request(sub, "");
fmt = ast_best_codec(tmp->nativeformats);
ast_string_field_build(tmp, name, "MGCP/%s@%s-%d", i->name, i->parent->name, sub->id);
if (sub->rtp)
- ast_channel_set_fd(tmp, 0, ast_rtp_fd(sub->rtp));
+ ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(sub->rtp, 0));
if (i->dtmfmode & (MGCP_DTMF_INBAND | MGCP_DTMF_HYBRID)) {
i->dsp = ast_dsp_new();
ast_dsp_set_features(i->dsp, DSP_FEATURE_DIGIT_DETECT);
sin.sin_family = AF_INET;
memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
sin.sin_port = htons(portno);
- ast_rtp_set_peer(sub->rtp, &sin);
+ ast_rtp_instance_set_remote_address(sub->rtp, &sin);
#if 0
printf("Peer RTP is at port %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
#endif
/* Scan through the RTP payload types specified in a "m=" line: */
- ast_rtp_pt_clear(sub->rtp);
+ ast_rtp_codecs_payloads_clear(ast_rtp_instance_get_codecs(sub->rtp), sub->rtp);
codecs = ast_strdupa(m + len);
while (!ast_strlen_zero(codecs)) {
if (sscanf(codecs, "%d%n", &codec, &len) != 1) {
ast_log(LOG_WARNING, "Error in codec string '%s' at '%s'\n", m, codecs);
return -1;
}
- ast_rtp_set_m_type(sub->rtp, codec);
+ ast_rtp_codecs_payloads_set_m_type(ast_rtp_instance_get_codecs(sub->rtp), sub->rtp, codec);
codec_count++;
codecs += len;
}
if (sscanf(a, "rtpmap: %u %[^/]/", &codec, mimeSubtype) != 2)
continue;
/* Note: should really look at the 'freq' and '#chans' params too */
- ast_rtp_set_rtpmap_type(sub->rtp, codec, "audio", mimeSubtype, 0);
+ ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(sub->rtp), sub->rtp, codec, "audio", mimeSubtype, 0);
}
/* Now gather all of the codecs that were asked for: */
- ast_rtp_get_current_formats(sub->rtp, &peercapability, &peerNonCodecCapability);
+ ast_rtp_codecs_payload_formats(ast_rtp_instance_get_codecs(sub->rtp), &peercapability, &peerNonCodecCapability);
p->capability = capability & peercapability;
if (mgcpdebug) {
ast_verbose("Capabilities: us - %d, them - %d, combined - %d\n",
}
-static int add_sdp(struct mgcp_request *resp, struct mgcp_subchannel *sub, struct ast_rtp *rtp)
+static int add_sdp(struct mgcp_request *resp, struct mgcp_subchannel *sub, struct ast_rtp_instance *rtp)
{
int len;
int codec;
ast_log(LOG_WARNING, "No way to add SDP without an RTP structure\n");
return -1;
}
- ast_rtp_get_us(sub->rtp, &sin);
+ ast_rtp_instance_get_local_address(sub->rtp, &sin);
if (rtp) {
- ast_rtp_get_peer(rtp, &dest);
+ ast_rtp_instance_get_remote_address(sub->rtp, &dest);
} else {
if (sub->tmpdest.sin_addr.s_addr) {
dest.sin_addr = sub->tmpdest.sin_addr;
if (mgcpdebug) {
ast_verbose("Answering with capability %d\n", x);
}
- codec = ast_rtp_lookup_code(sub->rtp, 1, x);
+ codec = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(sub->rtp), 1, x);
if (codec > -1) {
snprintf(costr, sizeof(costr), " %d", codec);
strncat(m, costr, sizeof(m) - strlen(m) - 1);
- snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, ast_rtp_lookup_mime_subtype(1, x, 0));
+ snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, ast_rtp_lookup_mime_subtype2(1, x, 0));
strncat(a, costr, sizeof(a) - strlen(a) - 1);
}
}
if (mgcpdebug) {
ast_verbose("Answering with non-codec capability %d\n", x);
}
- codec = ast_rtp_lookup_code(sub->rtp, 0, x);
+ codec = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(sub->rtp), 0, x);
if (codec > -1) {
snprintf(costr, sizeof(costr), " %d", codec);
strncat(m, costr, sizeof(m) - strlen(m) - 1);
- snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, ast_rtp_lookup_mime_subtype(0, x, 0));
+ snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, ast_rtp_lookup_mime_subtype2(0, x, 0));
strncat(a, costr, sizeof(a) - strlen(a) - 1);
if (x == AST_RTP_DTMF) {
/* Indicate we support DTMF... Not sure about 16,
return 0;
}
-static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp *rtp, int codecs)
+static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp_instance *rtp, int codecs)
{
struct mgcp_request resp;
char local[256];
if (ast_strlen_zero(sub->cxident) && rtp) {
/* We don't have a CXident yet, store the destination and
wait a bit */
- ast_rtp_get_peer(rtp, &sub->tmpdest);
+ ast_rtp_instance_get_remote_address(rtp, &sub->tmpdest);
return 0;
}
ast_copy_string(local, "p:20", sizeof(local));
for (x = 1; x <= AST_FORMAT_AUDIO_MASK; x <<= 1) {
if (p->capability & x) {
- snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype(1, x, 0));
+ snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype2(1, x, 0));
strncat(local, tmp, sizeof(local) - strlen(local) - 1);
}
}
return send_request(p, sub, &resp, oseq); /* SC */
}
-static int transmit_connect_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp *rtp)
+static int transmit_connect_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp_instance *rtp)
{
struct mgcp_request resp;
char local[256];
ast_copy_string(local, "p:20", sizeof(local));
for (x = 1; x <= AST_FORMAT_AUDIO_MASK; x <<= 1) {
if (p->capability & x) {
- snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype(1, x, 0));
+ snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype2(1, x, 0));
strncat(local, tmp, sizeof(local) - strlen(local) - 1);
}
}
ast_mutex_lock(&sub->lock);
/* check again to be on the safe side */
if (sub->rtp) {
- ast_rtp_destroy(sub->rtp);
+ ast_rtp_instance_destroy(sub->rtp);
sub->rtp = NULL;
}
/* Allocate the RTP now */
- sub->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
+ sub->rtp = ast_rtp_instance_new(NULL, sched, &bindaddr, NULL);
if (sub->rtp && sub->owner)
- ast_channel_set_fd(sub->owner, 0, ast_rtp_fd(sub->rtp));
+ ast_channel_set_fd(sub->owner, 0, ast_rtp_instance_fd(sub->rtp, 0));
if (sub->rtp) {
- ast_rtp_setqos(sub->rtp, qos.tos_audio, qos.cos_audio, "MGCP RTP");
- ast_rtp_setnat(sub->rtp, sub->nat);
+ ast_rtp_instance_set_qos(sub->rtp, qos.tos_audio, qos.cos_audio, "MGCP RTP");
+ ast_rtp_instance_set_prop(sub->rtp, AST_RTP_PROPERTY_NAT, sub->nat);
}
-#if 0
- ast_rtp_set_callback(p->rtp, rtpready);
- ast_rtp_set_data(p->rtp, p);
-#endif
/* Make a call*ID */
snprintf(sub->callid, sizeof(sub->callid), "%08lx%s", ast_random(), sub->txident);
/* Transmit the connection create */
return (gw_reload ? NULL : gw);
}
-static enum ast_rtp_get_result mgcp_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp)
+static enum ast_rtp_glue_result mgcp_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
{
struct mgcp_subchannel *sub = NULL;
if (!(sub = chan->tech_pvt) || !(sub->rtp))
- return AST_RTP_GET_FAILED;
+ return AST_RTP_GLUE_RESULT_FORBID;
- *rtp = sub->rtp;
+ *instance = sub->rtp ? ao2_ref(sub->rtp, +1), sub->rtp : NULL;
if (sub->parent->canreinvite)
- return AST_RTP_TRY_NATIVE;
+ return AST_RTP_GLUE_RESULT_REMOTE;
else
- return AST_RTP_TRY_PARTIAL;
+ return AST_RTP_GLUE_RESULT_LOCAL;
}
-static int mgcp_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active)
+static int mgcp_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, int codecs, int nat_active)
{
/* XXX Is there such thing as video support with MGCP? XXX */
struct mgcp_subchannel *sub;
return -1;
}
-static struct ast_rtp_protocol mgcp_rtp = {
+static struct ast_rtp_glue mgcp_rtp_glue = {
.type = "MGCP",
.get_rtp_info = mgcp_get_rtp_peer,
- .set_rtp_peer = mgcp_set_rtp_peer,
+ .update_peer = mgcp_set_rtp_peer,
};
static void destroy_endpoint(struct mgcp_endpoint *e)
transmit_connection_del(sub);
}
if (sub->rtp) {
- ast_rtp_destroy(sub->rtp);
+ ast_rtp_instance_destroy(sub->rtp);
sub->rtp = NULL;
}
memset(sub->magic, 0, sizeof(sub->magic));
return AST_MODULE_LOAD_FAILURE;
}
- ast_rtp_proto_register(&mgcp_rtp);
+ ast_rtp_glue_register(&mgcp_rtp_glue);
ast_cli_register_multiple(cli_mgcp, sizeof(cli_mgcp) / sizeof(struct ast_cli_entry));
/* And start the monitor for the first time */
}
close(mgcpsock);
- ast_rtp_proto_unregister(&mgcp_rtp);
+ ast_rtp_glue_unregister(&mgcp_rtp_glue);
ast_cli_unregister_multiple(cli_mgcp, sizeof(cli_mgcp) / sizeof(struct ast_cli_entry));
sched_context_destroy(sched);
#include "asterisk/pbx.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
-#include "asterisk/rtp.h"
+#include "asterisk/rtp_engine.h"
#include "asterisk/udptl.h"
#include "asterisk/acl.h"
#include "asterisk/manager.h"
#include "asterisk/ast_version.h"
#include "asterisk/event.h"
#include "asterisk/tcptls.h"
+#include "asterisk/stun.h"
/*** DOCUMENTATION
<application name="SIPDtmfMode" language="en_US">
AUTH_PEER_NOT_DYNAMIC = -6,
AUTH_ACL_FAILED = -7,
AUTH_BAD_TRANSPORT = -8,
+ AUTH_RTP_FAILED = 9,
};
/*! \brief States for outbound registrations (with register= lines in sip.conf */
#define DEFAULT_USERAGENT "Asterisk PBX" /*!< Default Useragent: header unless re-defined in sip.conf */
#define DEFAULT_SDPSESSION "Asterisk PBX" /*!< Default SDP session name, (s=) header unless re-defined in sip.conf */
#define DEFAULT_SDPOWNER "root" /*!< Default SDP username field in (o=) header unless re-defined in sip.conf */
+#define DEFAULT_ENGINE "asterisk" /*!< Default RTP engine to use for sessions */
#endif
/*@}*/
static char default_mohsuggest[MAX_MUSICCLASS]; /*!< Global setting for moh class to suggest when putting
* a bridged channel on hold */
static char default_parkinglot[AST_MAX_CONTEXT]; /*!< Parkinglot */
+static char default_engine[256]; /*!< Default RTP engine */
static int default_maxcallbitrate; /*!< Maximum bitrate for call */
static struct ast_codec_pref default_prefs; /*!< Default codec prefs */
static unsigned int default_transports; /*!< Default Transports (enum sip_transport) that are acceptable */
AST_STRING_FIELD(rpid_from); /*!< Our RPID From header */
AST_STRING_FIELD(url); /*!< URL to be sent with next message to peer */
AST_STRING_FIELD(parkinglot); /*!< Parkinglot */
+ AST_STRING_FIELD(engine); /*!< RTP engine to use */
);
char via[128]; /*!< Via: header */
struct sip_socket socket; /*!< The socket used for this dialog */
struct sip_peer *relatedpeer; /*!< If this dialog is related to a peer, which one
Used in peerpoke, mwi subscriptions */
struct sip_registry *registry; /*!< If this is a REGISTER dialog, to which registry */
- struct ast_rtp *rtp; /*!< RTP Session */
- struct ast_rtp *vrtp; /*!< Video RTP session */
- struct ast_rtp *trtp; /*!< Text RTP session */
+ struct ast_rtp_instance *rtp; /*!< RTP Session */
+ struct ast_rtp_instance *vrtp; /*!< Video RTP session */
+ struct ast_rtp_instance *trtp; /*!< Text RTP session */
struct sip_pkt *packets; /*!< Packets scheduled for re-transmission */
struct sip_history_head *history; /*!< History of this SIP dialog */
size_t history_entries; /*!< Number of entires in the history */
AST_STRING_FIELD(mohsuggest); /*!< Music on Hold class */
AST_STRING_FIELD(parkinglot); /*!< Parkinglot */
AST_STRING_FIELD(useragent); /*!< User agent in SIP request (saved from registration) */
+ AST_STRING_FIELD(engine); /*!< RTP Engine to use */
);
struct sip_socket socket; /*!< Socket used for this peer */
unsigned int transports:3; /*!< Transports (enum sip_transport) that are acceptable for this peer */
static int handle_response_register(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno);
static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno);
-/*----- RTP interface functions */
-static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active);
-static enum ast_rtp_get_result sip_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
-static enum ast_rtp_get_result sip_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
-static enum ast_rtp_get_result sip_get_trtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
-static int sip_get_codec(struct ast_channel *chan);
-static struct ast_frame *sip_rtp_read(struct ast_channel *ast, struct sip_pvt *p, int *faxdetect);
-
/*------ T38 Support --------- */
static int transmit_response_with_t38_sdp(struct sip_pvt *p, char *msg, struct sip_request *req, int retrans);
static struct ast_udptl *sip_get_udptl_peer(struct ast_channel *chan);
static enum st_mode st_get_mode(struct sip_pvt *);
static struct sip_st_dlg* sip_st_alloc(struct sip_pvt *const p);
+/*------- RTP Glue functions -------- */
+static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, int codecs, int nat_active);
+
/*!--- SIP MWI Subscription support */
static int sip_subscribe_mwi(const char *value, int lineno);
static void sip_subscribe_mwi_destroy(struct sip_subscription_mwi *mwi);
.fixup = sip_fixup, /* called with chan locked */
.send_digit_begin = sip_senddigit_begin, /* called with chan unlocked */
.send_digit_end = sip_senddigit_end,
- .bridge = ast_rtp_bridge, /* XXX chan unlocked ? */
- .early_bridge = ast_rtp_early_bridge,
+ .bridge = ast_rtp_instance_bridge, /* XXX chan unlocked ? */
+ .early_bridge = ast_rtp_instance_early_bridge,
.send_text = sip_sendtext, /* called with chan locked */
.func_channel_read = acf_channel_read,
.queryoption = sip_queryoption,
return errorvalue;
}
-
-/*! \brief Interface structure with callbacks used to connect to RTP module */
-static struct ast_rtp_protocol sip_rtp = {
- .type = "SIP",
- .get_rtp_info = sip_get_rtp_peer,
- .get_vrtp_info = sip_get_vrtp_peer,
- .get_trtp_info = sip_get_trtp_peer,
- .set_rtp_peer = sip_set_rtp_peer,
- .get_codec = sip_get_codec,
-};
-
/*!
* duplicate a list of channel variables, \return the copy.
*/
if (p->rtp) {
ast_debug(1, "Setting NAT on RTP to %s\n", mode);
- ast_rtp_setnat(p->rtp, natflags);
+ ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_NAT, natflags);
}
if (p->vrtp) {
ast_debug(1, "Setting NAT on VRTP to %s\n", mode);
- ast_rtp_setnat(p->vrtp, natflags);
+ ast_rtp_instance_set_prop(p->vrtp, AST_RTP_PROPERTY_NAT, natflags);
}
if (p->udptl) {
ast_debug(1, "Setting NAT on UDPTL to %s\n", mode);
}
if (p->trtp) {
ast_debug(1, "Setting NAT on TRTP to %s\n", mode);
- ast_rtp_setnat(p->trtp, natflags);
+ ast_rtp_instance_set_prop(p->trtp, AST_RTP_PROPERTY_NAT, natflags);
}
}
*to_sock = *from_sock;
}
+/*! \brief Initialize RTP portion of a dialog
+ * \returns -1 on failure, 0 on success
+ */
+static int dialog_initialize_rtp(struct sip_pvt *dialog)
+{
+ if (!sip_methods[dialog->method].need_rtp) {
+ return 0;
+ }
+
+ if (!(dialog->rtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr, NULL))) {
+ return -1;
+ }
+
+ if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT) && (dialog->capability & AST_FORMAT_VIDEO_MASK)) {
+ if (!(dialog->vrtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr, NULL))) {
+ return -1;
+ }
+ ast_rtp_instance_set_timeout(dialog->vrtp, global_rtptimeout);
+ ast_rtp_instance_set_hold_timeout(dialog->vrtp, global_rtpholdtimeout);
+
+ ast_rtp_instance_set_prop(dialog->vrtp, AST_RTP_PROPERTY_RTCP, 1);
+ }
+
+ if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_TEXTSUPPORT)) {
+ if (!(dialog->trtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr, NULL))) {
+ return -1;
+ }
+ ast_rtp_instance_set_timeout(dialog->trtp, global_rtptimeout);
+ ast_rtp_instance_set_hold_timeout(dialog->trtp, global_rtpholdtimeout);
+
+ ast_rtp_instance_set_prop(dialog->trtp, AST_RTP_PROPERTY_RTCP, 1);
+ }
+
+ ast_rtp_instance_set_timeout(dialog->rtp, global_rtptimeout);
+ ast_rtp_instance_set_hold_timeout(dialog->rtp, global_rtpholdtimeout);
+
+ ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_RTCP, 1);
+ ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF, ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
+ ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF_COMPENSATE, ast_test_flag(&dialog->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
+
+ ast_rtp_instance_set_qos(dialog->rtp, global_tos_audio, 0, "SIP RTP");
+
+ return 0;
+}
+
/*! \brief Create address structure from peer reference.
* This function copies data from peer to the dialog, so we don't have to look up the peer
* again from memory or database during the life time of the dialog.
ast_copy_flags(&dialog->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY);
ast_copy_flags(&dialog->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY);
dialog->capability = peer->capability;
- if (!ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS) &&
- (!ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT) ||
- !(dialog->capability & AST_FORMAT_VIDEO_MASK)) &&
- dialog->vrtp) {
- ast_rtp_destroy(dialog->vrtp);
- dialog->vrtp = NULL;
- }
- if (!ast_test_flag(&dialog->flags[1], SIP_PAGE2_TEXTSUPPORT) && dialog->trtp) {
- ast_rtp_destroy(dialog->trtp);
- dialog->trtp = NULL;
- }
dialog->prefs = peer->prefs;
if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_T38SUPPORT)) {
if (!dialog->udptl) {
}
do_setnat(dialog, ast_test_flag(&dialog->flags[0], SIP_NAT) & SIP_NAT_ROUTE);
+ ast_string_field_set(dialog, engine, peer->engine);
+
+ if (dialog_initialize_rtp(dialog)) {
+ return -1;
+ }
+
if (dialog->rtp) { /* Audio */
- ast_rtp_setdtmf(dialog->rtp, ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
- ast_rtp_setdtmfcompensate(dialog->rtp, ast_test_flag(&dialog->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
- ast_rtp_set_rtptimeout(dialog->rtp, peer->rtptimeout);
- ast_rtp_set_rtpholdtimeout(dialog->rtp, peer->rtpholdtimeout);
- ast_rtp_set_rtpkeepalive(dialog->rtp, peer->rtpkeepalive);
+ ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF, ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
+ ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF_COMPENSATE, ast_test_flag(&dialog->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
+ ast_rtp_instance_set_timeout(dialog->rtp, peer->rtptimeout);
+ ast_rtp_instance_set_hold_timeout(dialog->rtp, peer->rtpholdtimeout);
/* Set Frame packetization */
- ast_rtp_codec_setpref(dialog->rtp, &dialog->prefs);
+ ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(dialog->rtp), dialog->rtp, &dialog->prefs);
dialog->autoframing = peer->autoframing;
}
if (dialog->vrtp) { /* Video */
- ast_rtp_setdtmf(dialog->vrtp, 0);
- ast_rtp_setdtmfcompensate(dialog->vrtp, 0);
- ast_rtp_set_rtptimeout(dialog->vrtp, peer->rtptimeout);
- ast_rtp_set_rtpholdtimeout(dialog->vrtp, peer->rtpholdtimeout);
- ast_rtp_set_rtpkeepalive(dialog->vrtp, peer->rtpkeepalive);
+ ast_rtp_instance_set_timeout(dialog->vrtp, peer->rtptimeout);
+ ast_rtp_instance_set_hold_timeout(dialog->vrtp, peer->rtpholdtimeout);
}
if (dialog->trtp) { /* Realtime text */
- ast_rtp_setdtmf(dialog->trtp, 0);
- ast_rtp_setdtmfcompensate(dialog->trtp, 0);
- ast_rtp_set_rtptimeout(dialog->trtp, peer->rtptimeout);
- ast_rtp_set_rtpholdtimeout(dialog->trtp, peer->rtpholdtimeout);
- ast_rtp_set_rtpkeepalive(dialog->trtp, peer->rtpkeepalive);
+ ast_rtp_instance_set_timeout(dialog->trtp, peer->rtptimeout);
+ ast_rtp_instance_set_hold_timeout(dialog->trtp, peer->rtpholdtimeout);
}
ast_string_field_set(dialog, peername, peer->name);
ast_string_field_set(dialog, fullcontact, peer->fullcontact);
ast_string_field_set(dialog, context, peer->context);
ast_string_field_set(dialog, parkinglot, peer->parkinglot);
+ ast_string_field_set(dialog, engine, peer->engine);
ref_proxy(dialog, obproxy_get(dialog, peer));
dialog->callgroup = peer->callgroup;
dialog->pickupgroup = peer->pickupgroup;
return res;
}
+ if (dialog_initialize_rtp(dialog)) {
+ return -1;
+ }
+
do_setnat(dialog, ast_test_flag(&dialog->flags[0], SIP_NAT) & SIP_NAT_ROUTE);
ast_string_field_set(dialog, tohost, peername);
p->notify_headers = NULL;
}
if (p->rtp) {
- ast_rtp_destroy(p->rtp);
+ ast_rtp_instance_destroy(p->rtp);
}
if (p->vrtp) {
- ast_rtp_destroy(p->vrtp);
+ ast_rtp_instance_destroy(p->vrtp);
}
if (p->trtp) {
- while (ast_rtp_get_bridged(p->trtp))
- usleep(1);
- ast_rtp_destroy(p->trtp);
+ ast_rtp_instance_destroy(p->trtp);
}
if (p->udptl)
ast_udptl_destroy(p->udptl);
if (!p->pendinginvite) {
struct ast_channel *bridge = ast_bridged_channel(oldowner);
- char *audioqos = "";
- char *videoqos = "";
- char *textqos = "";
+ char quality_buf[AST_MAX_USER_FIELD], *quality;
- if (p->rtp)
- ast_rtp_set_vars(oldowner, p->rtp);
+ if (p->rtp) {
+ ast_rtp_instance_set_stats_vars(oldowner, p->rtp);
+ }
if (bridge) {
struct sip_pvt *q = bridge->tech_pvt;
- if (IS_SIP_TECH(bridge->tech) && q)
- ast_rtp_set_vars(bridge, q->rtp);
+ if (IS_SIP_TECH(bridge->tech) && q) {
+ ast_rtp_instance_set_stats_vars(bridge, q->rtp);
+ }
+ }
+
+ if (p->do_history || oldowner) {
+ if (p->rtp && (quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
+ if (p->do_history) {
+ append_history(p, "RTCPaudio", "Quality:%s", quality);
+ }
+ if (oldowner) {
+ pbx_builtin_setvar_helper(oldowner, "RTPAUDIOQOS", quality);
+ }
+ }
+ if (p->vrtp && (quality = ast_rtp_instance_get_quality(p->vrtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
+ if (p->do_history) {
+ append_history(p, "RTCPvideo", "Quality:%s", quality);
+ }
+ if (oldowner) {
+ pbx_builtin_setvar_helper(oldowner, "RTPVIDEOQOS", quality);
+ }
+ }
+ if (p->trtp && (quality = ast_rtp_instance_get_quality(p->trtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
+ if (p->do_history) {
+ append_history(p, "RTCPtext", "Quality:%s", quality);
+ }
+ if (oldowner) {
+ pbx_builtin_setvar_helper(oldowner, "RTPTEXTQOS", quality);
+ }
+ }
}
- if (p->vrtp)
- videoqos = ast_rtp_get_quality(p->vrtp, NULL, RTPQOS_SUMMARY);
- if (p->trtp)
- textqos = ast_rtp_get_quality(p->trtp, NULL, RTPQOS_SUMMARY);
/* Send a hangup */
transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1);
- /* Get RTCP quality before end of call */
- if (p->do_history) {
- if (p->rtp)
- append_history(p, "RTCPaudio", "Quality:%s", audioqos);
- if (p->vrtp)
- append_history(p, "RTCPvideo", "Quality:%s", videoqos);
- if (p->trtp)
- append_history(p, "RTCPtext", "Quality:%s", textqos);
- }
- if (p->rtp && oldowner)
- pbx_builtin_setvar_helper(oldowner, "RTPAUDIOQOS", audioqos);
- if (p->vrtp && oldowner)
- pbx_builtin_setvar_helper(oldowner, "RTPVIDEOQOS", videoqos);
- if (p->trtp && oldowner)
- pbx_builtin_setvar_helper(oldowner, "RTPTEXTQOS", textqos);
} else {
/* Note we will need a BYE when this all settles out
but we can't send one while we have "INVITE" outstanding. */
ast_setstate(ast, AST_STATE_UP);
ast_debug(1, "SIP answering channel: %s\n", ast->name);
- ast_rtp_new_source(p->rtp);
+ if (p->t38.state == T38_PEER_DIRECT) {
+ change_t38_state(p, T38_ENABLED);
+ }
+ ast_rtp_instance_new_source(p->rtp);
res = transmit_response_with_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL, FALSE);
ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
}
if ((ast->_state != AST_STATE_UP) &&
!ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) &&
!ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
- ast_rtp_new_source(p->rtp);
+ ast_rtp_instance_new_source(p->rtp);
p->invitestate = INV_EARLY_MEDIA;
transmit_response_with_sdp(p, "183 Session Progress", &p->initreq, XMIT_UNRELIABLE, FALSE);
ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT);
transmit_reinvite_with_sdp(p, FALSE, FALSE);
} else {
p->lastrtptx = time(NULL);
- res = ast_rtp_write(p->rtp, frame);
+ res = ast_rtp_instance_write(p->rtp, frame);
}
}
sip_pvt_unlock(p);
ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT);
}
p->lastrtptx = time(NULL);
- res = ast_rtp_write(p->vrtp, frame);
+ res = ast_rtp_instance_write(p->vrtp, frame);
}
sip_pvt_unlock(p);
}
if (p) {
sip_pvt_lock(p);
if (p->red) {
- ast_red_buffer_t140(p->trtp, frame);
+ ast_rtp_red_buffer(p->trtp, frame);
} else {
if (p->trtp) {
/* Activate text early media */
ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT);
}
p->lastrtptx = time(NULL);
- res = ast_rtp_write(p->trtp, frame);
+ res = ast_rtp_instance_write(p->trtp, frame);
}
}
sip_pvt_unlock(p);
sip_pvt_lock(p);
switch (ast_test_flag(&p->flags[0], SIP_DTMF)) {
case SIP_DTMF_INBAND:
- res = -1; /* Tell Asterisk to generate inband indications */
+ if (p->rtp && ast_rtp_instance_dtmf_mode_get(p->rtp) == AST_RTP_DTMF_MODE_INBAND) {
+ ast_rtp_instance_dtmf_begin(p->rtp, digit);
+ } else {
+ res = -1; /* Tell Asterisk to generate inband indications */
+ }
break;
case SIP_DTMF_RFC2833:
if (p->rtp)
- ast_rtp_senddigit_begin(p->rtp, digit);
+ ast_rtp_instance_dtmf_begin(p->rtp, digit);
break;
default:
break;
break;
case SIP_DTMF_RFC2833:
if (p->rtp)
- ast_rtp_senddigit_end(p->rtp, digit);
+ ast_rtp_instance_dtmf_end(p->rtp, digit);
break;
case SIP_DTMF_INBAND:
- res = -1; /* Tell Asterisk to stop inband indications */
+ if (p->rtp && ast_rtp_instance_dtmf_mode_get(p->rtp) == AST_RTP_DTMF_MODE_INBAND) {
+ ast_rtp_instance_dtmf_end(p->rtp, digit);
+ } else {
+ res = -1; /* Tell Asterisk to stop inband indications */
+ }
break;
}
sip_pvt_unlock(p);
res = -1;
break;
case AST_CONTROL_HOLD:
- ast_rtp_new_source(p->rtp);
+ ast_rtp_instance_new_source(p->rtp);
ast_moh_start(ast, data, p->mohinterpret);
break;
case AST_CONTROL_UNHOLD:
- ast_rtp_new_source(p->rtp);
+ ast_rtp_instance_new_source(p->rtp);
ast_moh_stop(ast);
break;
case AST_CONTROL_VIDUPDATE: /* Request a video frame update */
}
break;
case AST_CONTROL_SRCUPDATE:
- ast_rtp_new_source(p->rtp);
+ ast_rtp_instance_new_source(p->rtp);
break;
case -1:
res = -1;
ast_debug(3, "This channel will not be able to handle video.\n");
if ((ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) || (ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) {
- i->vad = ast_dsp_new();
- ast_dsp_set_features(i->vad, DSP_FEATURE_DIGIT_DETECT);
- if (global_relaxdtmf)
- ast_dsp_set_digitmode(i->vad, DSP_DIGITMODE_DTMF | DSP_DIGITMODE_RELAXDTMF);
+ if (!i->rtp || ast_rtp_instance_dtmf_mode_set(i->rtp, AST_RTP_DTMF_MODE_INBAND)) {
+ i->vad = ast_dsp_new();
+ ast_dsp_set_features(i->vad, DSP_FEATURE_DIGIT_DETECT);
+ if (global_relaxdtmf)
+ ast_dsp_set_digitmode(i->vad, DSP_DIGITMODE_DTMF | DSP_DIGITMODE_RELAXDTMF);
+ }
+ } else if (ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) {
+ if (i->rtp) {
+ ast_rtp_instance_dtmf_mode_set(i->rtp, AST_RTP_DTMF_MODE_RFC2833);
+ }
}
/* Set file descriptors for audio, video, realtime text and UDPTL as needed */
if (i->rtp) {
- ast_channel_set_fd(tmp, 0, ast_rtp_fd(i->rtp));
- ast_channel_set_fd(tmp, 1, ast_rtcp_fd(i->rtp));
+ ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(i->rtp, 0));
+ ast_channel_set_fd(tmp, 1, ast_rtp_instance_fd(i->rtp, 1));
}
if (needvideo && i->vrtp) {
- ast_channel_set_fd(tmp, 2, ast_rtp_fd(i->vrtp));
- ast_channel_set_fd(tmp, 3, ast_rtcp_fd(i->vrtp));
+ ast_channel_set_fd(tmp, 2, ast_rtp_instance_fd(i->vrtp, 0));
+ ast_channel_set_fd(tmp, 3, ast_rtp_instance_fd(i->vrtp, 1));
}
if (needtext && i->trtp)
- ast_channel_set_fd(tmp, 4, ast_rtp_fd(i->trtp));
+ ast_channel_set_fd(tmp, 4, ast_rtp_instance_fd(i->trtp, 0));
if (i->udptl)
ast_channel_set_fd(tmp, 5, ast_udptl_fd(i->udptl));
switch(ast->fdno) {
case 0:
- f = ast_rtp_read(p->rtp); /* RTP Audio */
+ f = ast_rtp_instance_read(p->rtp, 0); /* RTP Audio */
break;
case 1:
- f = ast_rtcp_read(p->rtp); /* RTCP Control Channel */
+ f = ast_rtp_instance_read(p->rtp, 1); /* RTCP Control Channel */
break;
case 2:
- f = ast_rtp_read(p->vrtp); /* RTP Video */
+ f = ast_rtp_instance_read(p->vrtp, 0); /* RTP Video */
break;
case 3:
- f = ast_rtcp_read(p->vrtp); /* RTCP Control Channel for video */
+ f = ast_rtp_instance_read(p->vrtp, 1); /* RTCP Control Channel for video */
break;
case 4:
- f = ast_rtp_read(p->trtp); /* RTP Text */
+ f = ast_rtp_instance_read(p->trtp, 0); /* RTP Text */
if (sipdebug_text) {
int i;
unsigned char* arr = f->data.ptr;
p->ocseq = INITIAL_CSEQ;
if (sip_methods[intended_method].need_rtp) {
- p->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
- /* If the global videosupport flag is on, we always create a RTP interface for video */
- if (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT))
- p->vrtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
- if (ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT))
- p->trtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
- if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT))
- p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, bindaddr.sin_addr);
- if (!p->rtp|| (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) && !p->vrtp)
- || (ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT) && !p->trtp)) {
- ast_log(LOG_WARNING, "Unable to create RTP audio %s%ssession: %s\n",
- ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "and video " : "",
- ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT) ? "and text " : "", strerror(errno));
- if (p->chanvars) {
- ast_variables_destroy(p->chanvars);
- p->chanvars = NULL;
- }
- ao2_t_ref(p, -1, "failed to create RTP audio session, drop p");
- return NULL;
- }
- ast_rtp_setqos(p->rtp, global_tos_audio, global_cos_audio, "SIP RTP");
- ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
- ast_rtp_setdtmfcompensate(p->rtp, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
- ast_rtp_set_rtptimeout(p->rtp, global_rtptimeout);
- ast_rtp_set_rtpholdtimeout(p->rtp, global_rtpholdtimeout);
- ast_rtp_set_rtpkeepalive(p->rtp, global_rtpkeepalive);
- if (p->vrtp) {
- ast_rtp_setqos(p->vrtp, global_tos_video, global_cos_video, "SIP VRTP");
- ast_rtp_setdtmf(p->vrtp, 0);
- ast_rtp_setdtmfcompensate(p->vrtp, 0);
- ast_rtp_set_rtptimeout(p->vrtp, global_rtptimeout);
- ast_rtp_set_rtpholdtimeout(p->vrtp, global_rtpholdtimeout);
- ast_rtp_set_rtpkeepalive(p->vrtp, global_rtpkeepalive);
- }
- if (p->trtp) {
- ast_rtp_setqos(p->trtp, global_tos_text, global_cos_text, "SIP TRTP");
- ast_rtp_setdtmf(p->trtp, 0);
- ast_rtp_setdtmfcompensate(p->trtp, 0);
- }
- if (p->udptl)
+ if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) && (p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, bindaddr.sin_addr))) {
ast_udptl_setqos(p->udptl, global_tos_audio, global_cos_audio);
+ }
p->maxcallbitrate = default_maxcallbitrate;
p->autoframing = global_autoframing;
- ast_rtp_codec_setpref(p->rtp, &p->prefs);
}
if (useglobal_nat && sin) {
}
ast_string_field_set(p, context, sip_cfg.default_context);
ast_string_field_set(p, parkinglot, default_parkinglot);
+ ast_string_field_set(p, engine, default_engine);
AST_LIST_HEAD_INIT_NOLOCK(&p->request_queue);
int iterator;
int sendonly = -1;
int numberofports;
- struct ast_rtp *newaudiortp, *newvideortp, *newtextrtp; /* Buffers for codec handling */
+ struct ast_rtp_codecs newaudiortp, newvideortp, newtextrtp;
int newjointcapability; /* Negotiated capability */
int newpeercapability;
int newnoncodeccapability;
return -1;
}
- /* Initialize the temporary RTP structures we use to evaluate the offer from the peer */
-#ifdef LOW_MEMORY
- newaudiortp = ast_threadstorage_get(&ts_audio_rtp, ast_rtp_alloc_size());
-#else
- newaudiortp = alloca(ast_rtp_alloc_size());
-#endif
- memset(newaudiortp, 0, ast_rtp_alloc_size());
- ast_rtp_new_init(newaudiortp);
- ast_rtp_pt_clear(newaudiortp);
-
-#ifdef LOW_MEMORY
- newvideortp = ast_threadstorage_get(&ts_video_rtp, ast_rtp_alloc_size());
-#else
- newvideortp = alloca(ast_rtp_alloc_size());
-#endif
- memset(newvideortp, 0, ast_rtp_alloc_size());
- ast_rtp_new_init(newvideortp);
- ast_rtp_pt_clear(newvideortp);
-
-#ifdef LOW_MEMORY
- newtextrtp = ast_threadstorage_get(&ts_text_rtp, ast_rtp_alloc_size());
-#else
- newtextrtp = alloca(ast_rtp_alloc_size());
-#endif
- memset(newtextrtp, 0, ast_rtp_alloc_size());
- ast_rtp_new_init(newtextrtp);
- ast_rtp_pt_clear(newtextrtp);
+ /* Make sure that the codec structures are all cleared out */
+ ast_rtp_codecs_payloads_clear(&newaudiortp, NULL);
+ ast_rtp_codecs_payloads_clear(&newvideortp, NULL);
+ ast_rtp_codecs_payloads_clear(&newtextrtp, NULL);
/* Update our last rtprx when we receive an SDP, too */
p->lastrtprx = p->lastrtptx = time(NULL); /* XXX why both ? */
p->novideo = TRUE;
p->notext = TRUE;
- if (p->vrtp)
- ast_rtp_pt_clear(newvideortp); /* Must be cleared in case no m=video line exists */
-
- if (p->trtp)
- ast_rtp_pt_clear(newtextrtp); /* Must be cleared in case no m=text line exists */
+ if (p->vrtp) {
+ ast_rtp_codecs_payloads_clear(&newvideortp, NULL);
+ }
+
+ if (p->trtp) {
+ ast_rtp_codecs_payloads_clear(&newtextrtp, NULL);
+ }
/* Find media streams in this SDP offer */
while ((m = get_sdp_iterate(&iterator, req, "m"))[0] != '\0') {
}
if (debug)
ast_verbose("Found RTP audio format %d\n", codec);
- ast_rtp_set_m_type(newaudiortp, codec);
+
+ ast_rtp_codecs_payloads_set_m_type(&newaudiortp, NULL, codec);
}
} else if ((sscanf(m, "video %d/%d RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) ||
(sscanf(m, "video %d RTP/AVP %n", &x, &len) == 1 && len >= 0)) {
}
if (debug)
ast_verbose("Found RTP video format %d\n", codec);
- ast_rtp_set_m_type(newvideortp, codec);
+ ast_rtp_codecs_payloads_set_m_type(&newvideortp, NULL, codec);
}
} else if ((sscanf(m, "text %d/%d RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) ||
(sscanf(m, "text %d RTP/AVP %n", &x, &len) == 1 && len > 0)) {
}
if (debug)
ast_verbose("Found RTP text format %d\n", codec);
- ast_rtp_set_m_type(newtextrtp, codec);
+ ast_rtp_codecs_payloads_set_m_type(&newtextrtp, NULL, codec);
}
} else if (p->udptl && ( (sscanf(m, "image %d udptl t38%n", &x, &len) == 1 && len > 0) ||
(sscanf(m, "image %d UDPTL t38%n", &x, &len) == 1 && len > 0) )) {
if (udptlportno > 0) {
sin.sin_port = htons(udptlportno);
if (ast_test_flag(&p->flags[0], SIP_NAT) && ast_test_flag(&p->flags[1], SIP_PAGE2_UDPTL_DESTINATION)) {
- struct sockaddr_in peer;
- ast_rtp_get_peer(p->rtp, &peer);
- if (peer.sin_addr.s_addr) {
- memcpy(&sin.sin_addr, &peer.sin_addr, sizeof(sin.sin_addr));
+ struct sockaddr_in remote_address;
+ ast_rtp_instance_get_remote_address(p->rtp, &remote_address);
+ if (remote_address.sin_addr.s_addr) {
+ memcpy(&sin, &remote_address, sizeof(sin));
if (debug) {
ast_log(LOG_DEBUG, "Peer T.38 UDPTL is set behind NAT and with destination, destination address now %s\n", ast_inet_ntoa(sin.sin_addr));
}
if (p->rtp) {
if (portno > 0) {
sin.sin_port = htons(portno);
- ast_rtp_set_peer(p->rtp, &sin);
+ ast_rtp_instance_set_remote_address(p->rtp, &sin);
if (debug)
ast_verbose("Peer audio RTP is at port %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
} else {
if (debug)
ast_verbose("Got T.38 Re-invite without audio. Keeping RTP active during T.38 session. Callid %s\n", p->callid);
} else {
- ast_rtp_stop(p->rtp);
+ ast_rtp_instance_stop(p->rtp);
if (debug)
ast_verbose("Peer doesn't provide audio. Callid %s\n", p->callid);
}
}
}
if (framing && p->autoframing) {
- struct ast_codec_pref *pref = ast_rtp_codec_getpref(p->rtp);
+ struct ast_codec_pref *pref = &ast_rtp_instance_get_codecs(p->rtp)->pref;
int codec_n;
- int format = 0;
- for (codec_n = 0; codec_n < MAX_RTP_PT; codec_n++) {
- format = ast_rtp_codec_getformat(codec_n);
- if (!format) /* non-codec or not found */
+ for (codec_n = 0; codec_n < AST_RTP_MAX_PT; codec_n++) {
+ struct ast_rtp_payload_type format = ast_rtp_codecs_payload_lookup(ast_rtp_instance_get_codecs(p->rtp), codec_n);
+ if (!format.asterisk_format || !format.code) /* non-codec or not found */
continue;
if (option_debug)
- ast_log(LOG_DEBUG, "Setting framing for %d to %ld\n", format, framing);
- ast_codec_pref_setsize(pref, format, framing);
+ ast_log(LOG_DEBUG, "Setting framing for %d to %ld\n", format.code, framing);
+ ast_codec_pref_setsize(pref, format.code, framing);
}
- ast_rtp_codec_setpref(p->rtp, pref);
+ ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, pref);
}
continue;
}
sscanf(red_cp, "%u", &red_data_pt[red_num_gen]);
red_cp = strtok(red_cp, "/");
- while (red_cp && red_num_gen++ < RED_MAX_GENERATION) {
+ while (red_cp && red_num_gen++ < AST_RED_MAX_GENERATION) {
sscanf(red_cp, "%u", &red_data_pt[red_num_gen]);
red_cp = strtok(NULL, "/");
}
}
if (sscanf(a, "fmtp: %u %63s", &codec, fmtp_string) == 2) {
- struct rtpPayloadType payload;
+ struct ast_rtp_payload_type payload;
unsigned int handled = 0;
- payload = ast_rtp_lookup_pt(newaudiortp, codec);
+ payload = ast_rtp_codecs_payload_lookup(&newaudiortp, codec);
if (!payload.code) {
/* it wasn't found, try the video rtp */
- payload = ast_rtp_lookup_pt(newvideortp, codec);
+ payload = ast_rtp_codecs_payload_lookup(&newvideortp, codec);
}
- if (payload.code && payload.isAstFormat) {
+ if (payload.code && payload.asterisk_format) {
unsigned int bit_rate;
switch (payload.code) {
if (sscanf(fmtp_string, "bitrate=%u", &bit_rate) == 1) {
if (bit_rate != 32000) {
ast_log(LOG_WARNING, "Got Siren7 offer at %d bps, but only 32000 bps supported; ignoring.\n", bit_rate);
- ast_rtp_unset_m_type(newaudiortp, codec);
+ ast_rtp_codecs_payloads_unset(&newaudiortp, NULL, codec);
} else {
handled = 1;
}
if (sscanf(fmtp_string, "bitrate=%u", &bit_rate) == 1) {
if (bit_rate != 48000) {
ast_log(LOG_WARNING, "Got Siren14 offer at %d bps, but only 48000 bps supported; ignoring.\n", bit_rate);
- ast_rtp_unset_m_type(newaudiortp, codec);
+ ast_rtp_codecs_payloads_unset(&newaudiortp, NULL, codec);
} else {
handled = 1;
}
/* Note: should really look at the '#chans' params too */
/* Note: This should all be done in the context of the m= above */
if (!strncasecmp(mimeSubtype, "H26", 3) || !strncasecmp(mimeSubtype, "MP4", 3)) { /* Video */
- if (ast_rtp_set_rtpmap_type_rate(newvideortp, codec, "video", mimeSubtype, 0, sample_rate) != -1) {
+ if (ast_rtp_codecs_payloads_set_rtpmap_type_rate(&newvideortp, NULL, codec, "video", mimeSubtype, 0, sample_rate) != -1) {
if (debug)
ast_verbose("Found video description format %s for ID %d\n", mimeSubtype, codec);
found_rtpmap_codecs[last_rtpmap_codec] = codec;
last_rtpmap_codec++;
} else {
- ast_rtp_unset_m_type(newvideortp, codec);
+ ast_rtp_codecs_payloads_unset(&newvideortp, NULL, codec);
if (debug)
ast_verbose("Found unknown media description format %s for ID %d\n", mimeSubtype, codec);
}
} else if (!strncasecmp(mimeSubtype, "T140", 4)) { /* Text */
if (p->trtp) {
/* ast_verbose("Adding t140 mimeSubtype to textrtp struct\n"); */
- ast_rtp_set_rtpmap_type(newtextrtp, codec, "text", mimeSubtype, 0);
+ ast_rtp_codecs_payloads_set_rtpmap_type_rate(&newtextrtp, NULL, codec, "text", mimeSubtype, 0, sample_rate);
}
} else if (!strncasecmp(mimeSubtype, "RED", 3)) { /* Text with Redudancy */
if (p->trtp) {
- ast_rtp_set_rtpmap_type(newtextrtp, codec, "text", mimeSubtype, 0);
+ ast_rtp_codecs_payloads_set_rtpmap_type_rate(&newtextrtp, NULL, codec, "text", mimeSubtype, 0, sample_rate);
red_pt = codec;
sprintf(red_fmtp, "fmtp:%d ", red_pt);
ast_verbose("RED submimetype has payload type: %d\n", red_pt);
}
} else { /* Must be audio?? */
- if (ast_rtp_set_rtpmap_type_rate(newaudiortp, codec, "audio", mimeSubtype,
- ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0,
- sample_rate) != -1) {
+ if (ast_rtp_codecs_payloads_set_rtpmap_type_rate(&newaudiortp, NULL, codec, "audio", mimeSubtype,
+ ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0, sample_rate) != -1) {
if (debug)
ast_verbose("Found audio description format %s for ID %d\n", mimeSubtype, codec);
found_rtpmap_codecs[last_rtpmap_codec] = codec;
last_rtpmap_codec++;
} else {
- ast_rtp_unset_m_type(newaudiortp, codec);
+ ast_rtp_codecs_payloads_unset(&newaudiortp, NULL, codec);
if (debug)
ast_verbose("Found unknown media description format %s for ID %d\n", mimeSubtype, codec);
}
}
/* Now gather all of the codecs that we are asked for: */
- ast_rtp_get_current_formats(newaudiortp, &peercapability, &peernoncodeccapability);
- ast_rtp_get_current_formats(newvideortp, &vpeercapability, &vpeernoncodeccapability);
- ast_rtp_get_current_formats(newtextrtp, &tpeercapability, &tpeernoncodeccapability);
+ ast_rtp_codecs_payload_formats(&newaudiortp, &peercapability, &peernoncodeccapability);
+ ast_rtp_codecs_payload_formats(&newvideortp, &vpeercapability, &vpeernoncodeccapability);
+ ast_rtp_codecs_payload_formats(&newtextrtp, &tpeercapability, &tpeernoncodeccapability);
newjointcapability = p->capability & (peercapability | vpeercapability | tpeercapability);
newpeercapability = (peercapability | vpeercapability | tpeercapability);
newnoncodeccapability = p->noncodeccapability & peernoncodeccapability;
-
-
+
if (debug) {
/* shame on whoever coded this.... */
char s1[SIPBUFSIZE], s2[SIPBUFSIZE], s3[SIPBUFSIZE], s4[SIPBUFSIZE], s5[SIPBUFSIZE];
ast_getformatname_multiple(s3, SIPBUFSIZE, vpeercapability),
ast_getformatname_multiple(s4, SIPBUFSIZE, tpeercapability),
ast_getformatname_multiple(s5, SIPBUFSIZE, newjointcapability));
+ }
+
+ if (debug) {
+ struct ast_str *s1 = ast_str_alloca(SIPBUFSIZE);
+ struct ast_str *s2 = ast_str_alloca(SIPBUFSIZE);
+ struct ast_str *s3 = ast_str_alloca(SIPBUFSIZE);
ast_verbose("Non-codec capabilities (dtmf): us - %s, peer - %s, combined - %s\n",
- ast_rtp_lookup_mime_multiple(s1, SIPBUFSIZE, p->noncodeccapability, 0, 0),
- ast_rtp_lookup_mime_multiple(s2, SIPBUFSIZE, peernoncodeccapability, 0, 0),
- ast_rtp_lookup_mime_multiple(s3, SIPBUFSIZE, newnoncodeccapability, 0, 0));
+ ast_rtp_lookup_mime_multiple2(s1, p->noncodeccapability, 0, 0),
+ ast_rtp_lookup_mime_multiple2(s2, peernoncodeccapability, 0, 0),
+ ast_rtp_lookup_mime_multiple2(s3, newnoncodeccapability, 0, 0));
}
if (!newjointcapability) {
/* If T.38 was not negotiated either, totally bail out... */
p->red = 0;
}
- ast_rtp_pt_copy(p->rtp, newaudiortp);
- if (p->vrtp)
- ast_rtp_pt_copy(p->vrtp, newvideortp);
- if (p->trtp)
- ast_rtp_pt_copy(p->trtp, newtextrtp);
+ ast_rtp_codecs_payloads_copy(&newaudiortp, ast_rtp_instance_get_codecs(p->rtp), p->rtp);
+ if (p->vrtp) {
+ ast_rtp_codecs_payloads_copy(&newvideortp, ast_rtp_instance_get_codecs(p->vrtp), p->vrtp);
+ }
+ if (p->trtp) {
+ ast_rtp_codecs_payloads_copy(&newtextrtp, ast_rtp_instance_get_codecs(p->trtp), p->trtp);
+ }
if (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO) {
ast_clear_flag(&p->flags[0], SIP_DTMF);
/* XXX Would it be reasonable to drop the DSP at this point? XXX */
ast_set_flag(&p->flags[0], SIP_DTMF_RFC2833);
/* Since RFC2833 is now negotiated we need to change some properties of the RTP stream */
- ast_rtp_setdtmf(p->rtp, 1);
- ast_rtp_setdtmfcompensate(p->rtp, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
+ ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_DTMF, 1);
+ ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_DTMF_COMPENSATE, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
} else {
ast_set_flag(&p->flags[0], SIP_DTMF_INBAND);
}
/* Setup audio port number */
if (p->rtp && sin.sin_port) {
- ast_rtp_set_peer(p->rtp, &sin);
+ ast_rtp_instance_set_remote_address(p->rtp, &sin);
if (debug)
ast_verbose("Peer audio RTP is at port %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
}
/* Setup video port number */
if (p->vrtp && vsin.sin_port) {
- ast_rtp_set_peer(p->vrtp, &vsin);
+ ast_rtp_instance_set_remote_address(p->vrtp, &vsin);
if (debug)
ast_verbose("Peer video RTP is at port %s:%d\n", ast_inet_ntoa(vsin.sin_addr), ntohs(vsin.sin_port));
}
/* Setup text port number */
if (p->trtp && tsin.sin_port) {
- ast_rtp_set_peer(p->trtp, &tsin);
+ ast_rtp_instance_set_remote_address(p->trtp, &tsin);
if (debug)
ast_verbose("Peer text RTP is at port %s:%d\n", ast_inet_ntoa(tsin.sin_addr), ntohs(tsin.sin_port));
}
S_OR(p->mohsuggest, NULL),
!ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
if (sendonly)
- ast_rtp_stop(p->rtp);
+ ast_rtp_instance_stop(p->rtp);
/* RTCP needs to go ahead, even if we're on hold!!! */
/* Activate a re-invite */
ast_queue_frame(p->owner, &ast_null_frame);
if (debug)
ast_verbose("Adding codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec));
- if ((rtp_code = ast_rtp_lookup_code(p->rtp, 1, codec)) == -1)
+ if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->rtp), 1, codec)) == -1)
return;
if (p->rtp) {
- struct ast_codec_pref *pref = ast_rtp_codec_getpref(p->rtp);
+ struct ast_codec_pref *pref = &ast_rtp_instance_get_codecs(p->rtp)->pref;
fmt = ast_codec_pref_getsize(pref, codec);
} else /* I dont see how you couldn't have p->rtp, but good to check for and error out if not there like earlier code */
return;
ast_str_append(m_buf, 0, " %d", rtp_code);
ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code,
- ast_rtp_lookup_mime_subtype(1, codec,
+ ast_rtp_lookup_mime_subtype2(1, codec,
ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0),
- ast_rtp_lookup_sample_rate(1, codec));
+ ast_rtp_lookup_sample_rate2(1, codec));
switch (codec) {
case AST_FORMAT_G729A:
if (debug)
ast_verbose("Adding video codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec));
- if ((rtp_code = ast_rtp_lookup_code(p->vrtp, 1, codec)) == -1)
+ if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->vrtp), 1, codec)) == -1)
return;
ast_str_append(m_buf, 0, " %d", rtp_code);
ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code,
- ast_rtp_lookup_mime_subtype(1, codec, 0),
- ast_rtp_lookup_sample_rate(1, codec));
+ ast_rtp_lookup_mime_subtype2(1, codec, 0),
+ ast_rtp_lookup_sample_rate2(1, codec));
/* Add fmtp code here */
}
if (debug)
ast_verbose("Adding text codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec));
- if ((rtp_code = ast_rtp_lookup_code(p->trtp, 1, codec)) == -1)
+ if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->trtp), 1, codec)) == -1)
return;
ast_str_append(m_buf, 0, " %d", rtp_code);
ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code,
- ast_rtp_lookup_mime_subtype(1, codec, 0),
- ast_rtp_lookup_sample_rate(1, codec));
+ ast_rtp_lookup_mime_subtype2(1, codec, 0),
+ ast_rtp_lookup_sample_rate2(1, codec));
/* Add fmtp code here */
if (codec == AST_FORMAT_T140RED) {
- ast_str_append(a_buf, 0, "a=fmtp:%d %d/%d/%d\r\n", rtp_code,
- ast_rtp_lookup_code(p->trtp, 1, AST_FORMAT_T140),
- ast_rtp_lookup_code(p->trtp, 1, AST_FORMAT_T140),
- ast_rtp_lookup_code(p->trtp, 1, AST_FORMAT_T140));
+ int t140code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->trtp), 1, AST_FORMAT_T140);
+ ast_str_append(a_buf, 0, "a=fmtp:%d %d/%d/%d\r\n", rtp_code,
+ t140code,
+ t140code,
+ t140code);
}
}
int rtp_code;
if (debug)
- ast_verbose("Adding non-codec 0x%x (%s) to SDP\n", format, ast_rtp_lookup_mime_subtype(0, format, 0));
- if ((rtp_code = ast_rtp_lookup_code(p->rtp, 0, format)) == -1)
+ ast_verbose("Adding non-codec 0x%x (%s) to SDP\n", format, ast_rtp_lookup_mime_subtype2(0, format, 0));
+ if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->rtp), 0, format)) == -1)
return;
ast_str_append(m_buf, 0, " %d", rtp_code);
ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code,
- ast_rtp_lookup_mime_subtype(0, format, 0),
- ast_rtp_lookup_sample_rate(0, format));
+ ast_rtp_lookup_mime_subtype2(0, format, 0),
+ ast_rtp_lookup_sample_rate2(0, format));
if (format == AST_RTP_DTMF) /* Indicate we support DTMF and FLASH... */
ast_str_append(a_buf, 0, "a=fmtp:%d 0-16\r\n", rtp_code);
}
struct sockaddr_in *dest, struct sockaddr_in *vdest)
{
/* First, get our address */
- ast_rtp_get_us(p->rtp, sin);
+ ast_rtp_instance_get_local_address(p->rtp, sin);
if (p->vrtp)
- ast_rtp_get_us(p->vrtp, vsin);
+ ast_rtp_instance_get_local_address(p->vrtp, vsin);
if (p->trtp)
- ast_rtp_get_us(p->trtp, tsin);
+ ast_rtp_instance_get_local_address(p->trtp, tsin);
/* Now, try to figure out where we want them to send data */
/* Is this a re-invite to move the media out, then use the original offer from caller */
if (p->rtp) {
if (!p->autoframing && !ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
ast_debug(1, "Setting framing from config on incoming call\n");
- ast_rtp_codec_setpref(p->rtp, &p->prefs);
+ ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, &p->prefs);
}
try_suggested_sip_codec(p);
if (p->t38.state == T38_PEER_DIRECT || p->t38.state == T38_ENABLED) {
}
if (peer) {
- /*! \todo OEJ Remove this - there's never RTP in a REGISTER dialog... */
- /* Set Frame packetization */
- if (p->rtp) {
- ast_rtp_codec_setpref(p->rtp, &peer->prefs);
- p->autoframing = peer->autoframing;
- }
if (!peer->host_dynamic) {
ast_log(LOG_ERROR, "Peer '%s' is trying to register, but not configured as host=dynamic\n", peer->name);
res = AUTH_PEER_NOT_DYNAMIC;
/* XXX what about p->prefs = peer->prefs; ? */
/* Set Frame packetization */
if (p->rtp) {
- ast_rtp_codec_setpref(p->rtp, &peer->prefs);
+ ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, &peer->prefs);
p->autoframing = peer->autoframing;
}
ast_string_field_set(p, mohinterpret, peer->mohinterpret);
ast_string_field_set(p, mohsuggest, peer->mohsuggest);
ast_string_field_set(p, parkinglot, peer->parkinglot);
+ ast_string_field_set(p, engine, peer->engine);
if (peer->callingpres) /* Peer calling pres setting will override RPID */
p->callingpres = peer->callingpres;
if (peer->maxms && peer->lastms)
if (p->peercapability)
p->jointcapability &= p->peercapability;
p->maxcallbitrate = peer->maxcallbitrate;
- if (!ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS) &&
- (!ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) ||
- !(p->capability & AST_FORMAT_VIDEO_MASK)) &&
- p->vrtp) {
- ast_rtp_destroy(p->vrtp);
- p->vrtp = NULL;
- }
- if ((!ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT) || !(p->capability & AST_FORMAT_TEXT_MASK)) && p->trtp) {
- ast_rtp_destroy(p->trtp);
- p->trtp = NULL;
- }
if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) ||
(ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO))
p->noncodeccapability |= AST_RTP_DTMF;
p->jointnoncodeccapability = p->noncodeccapability;
if (p->t38.peercapability)
p->t38.jointcapability &= p->t38.peercapability;
+ if (!dialog_initialize_rtp(p)) {
+ ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, &peer->prefs);
+ p->autoframing = peer->autoframing;
+ } else {
+ res = AUTH_RTP_FAILED;
+ }
}
unref_peer(peer, "check_peer_ok: unref_peer: tossing temp ptr to peer from find_peer");
return res;
/* Finally, apply the guest policy */
if (sip_cfg.allowguest) {
replace_cid(p, rpid_num, calleridname);
- res = AUTH_SUCCESSFUL;
+ if (!dialog_initialize_rtp(p)) {
+ res = AUTH_SUCCESSFUL;
+ } else {
+ res = AUTH_RTP_FAILED;
+ }
} else if (sip_cfg.alwaysauthreject)
res = AUTH_FAKE_AUTH; /* reject with fake authorization request */
else
*/
return 0;
}
-
+
+ /* We absolutely cannot destroy the rtp struct while a bridge is active or we WILL crash */
+ if (dialog->rtp && ast_rtp_instance_get_bridged(dialog->rtp)) {
+ ast_debug(2, "Bridge still active. Delaying destroy of SIP dialog '%s' Method: %s\n", dialog->callid, sip_methods[dialog->method].text);
+ sip_pvt_unlock(dialog);
+ return 0;
+ }
+
+ if (dialog->vrtp && ast_rtp_instance_get_bridged(dialog->vrtp)) {
+ ast_debug(2, "Bridge still active. Delaying destroy of SIP dialog '%s' Method: %s\n", dialog->callid, sip_methods[dialog->method].text);
+ sip_pvt_unlock(dialog);
+ return 0;
+ }
+
/* Check RTP timeouts and kill calls if we have a timeout set and do not get RTP */
check_rtp_timeout(dialog, *t);
- if that's the case, wait with destruction */
if (dialog->needdestroy && !dialog->packets && !dialog->owner) {
/* We absolutely cannot destroy the rtp struct while a bridge is active or we WILL crash */
- if (dialog->rtp && ast_rtp_get_bridged(dialog->rtp)) {
+ if (dialog->rtp && ast_rtp_instance_get_bridged(dialog->rtp)) {
ast_debug(2, "Bridge still active. Delaying destruction of SIP dialog '%s' Method: %s\n", dialog->callid, sip_methods[dialog->method].text);
sip_pvt_unlock(dialog);
return 0;
}
- if (dialog->vrtp && ast_rtp_get_bridged(dialog->vrtp)) {
+ if (dialog->vrtp && ast_rtp_instance_get_bridged(dialog->vrtp)) {
ast_debug(2, "Bridge still active. Delaying destroy of SIP dialog '%s' Method: %s\n", dialog->callid, sip_methods[dialog->method].text);
sip_pvt_unlock(dialog);
return 0;
ast_cli(fd, " Sess-Refresh : %s\n", strefresher2str(peer->stimer.st_ref));
ast_cli(fd, " Sess-Expires : %d secs\n", peer->stimer.st_max_se);
ast_cli(fd, " Min-Sess : %d secs\n", peer->stimer.st_min_se);
+ ast_cli(fd, " RTP Engine : %s\n", peer->engine);
ast_cli(fd, "\n");
peer = unref_peer(peer, "sip_show_peer: unref_peer: done with peer ptr");
} else if (peer && type == 1) { /* manager listing */
astman_append(s, "SIP-Sess-Refresh: %s\r\n", strefresher2str(peer->stimer.st_ref));
astman_append(s, "SIP-Sess-Expires: %d\r\n", peer->stimer.st_max_se);
astman_append(s, "SIP-Sess-Min: %d\r\n", peer->stimer.st_min_se);
+ astman_append(s, "SIP-RTP-Engine: %s\r\n", peer->engine);
/* - is enumerated */
astman_append(s, "SIP-DTMFmode: %s\r\n", dtmfmode2str(ast_test_flag(&peer->flags[0], SIP_DTMF)));
ast_cli(a->fd, " Sess-Refresh : %s\n", strefresher2str(user->stimer.st_ref));
ast_cli(a->fd, " Sess-Expires : %d secs\n", user->stimer.st_max_se);
ast_cli(a->fd, " Sess-Min-SE : %d secs\n", user->stimer.st_min_se);
+ ast_cli(a->fd, " RTP Engine : %s\n", user->engine);
ast_cli(a->fd, " Codec Order : (");
print_codec_to_cli(a->fd, &user->prefs);
#define FORMAT2 "%-15.15s %-11.11s %-8.8s %-10.10s %-10.10s (%-2.2s) %-6.6s %-10.10s %-10.10s ( %%) %-6.6s\n"
#define FORMAT "%-15.15s %-11.11s %-8.8s %-10.10u%-1.1s %-10.10u (%-2.2u%%) %-6.6u %-10.10u%-1.1s %-10.10u (%-2.2u%%) %-6.6u\n"
struct sip_pvt *cur = __cur;
- unsigned int rxcount;
- unsigned int txcount;
+ struct ast_rtp_instance_stats stats;
char durbuf[10];
- int duration;
- int durh, durm, durs;
+ int duration;
+ int durh, durm, durs;
struct ast_channel *c = cur->owner;
struct __show_chan_arg *arg = __arg;
int fd = arg->fd;
ast_cli(fd, "%-15.15s %-11.11s (inv state: %s) -- %s\n", ast_inet_ntoa(cur->sa.sin_addr), cur->callid, invitestate2string[cur->invitestate].desc, "-- No RTP active");
return 0; /* don't care, we scan all channels */
}
- rxcount = ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXCOUNT);
- txcount = ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXCOUNT);
- /* Find the duration of this channel */
+ ast_rtp_instance_get_stats(cur->rtp, &stats, AST_RTP_INSTANCE_STAT_ALL);
+
if (c && c->cdr && !ast_tvzero(c->cdr->start)) {
duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000);
durh = duration / 3600;
} else {
durbuf[0] = '\0';
}
- /* Print stats for every call with RTP */
+
ast_cli(fd, FORMAT,
ast_inet_ntoa(cur->sa.sin_addr),
cur->callid,
durbuf,
- rxcount > (unsigned int) 100000 ? (unsigned int) (rxcount)/(unsigned int) 1000 : rxcount,
- rxcount > (unsigned int) 100000 ? "K":" ",
- ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXPLOSS),
- rxcount > ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXPLOSS) ? (unsigned int) (ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXPLOSS) / rxcount * 100) : 0,
- ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXJITTER),
- txcount > (unsigned int) 100000 ? (unsigned int) (txcount)/(unsigned int) 1000 : txcount,
- txcount > (unsigned int) 100000 ? "K":" ",
- ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXPLOSS),
- txcount > ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXPLOSS) ? (unsigned int) (ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXPLOSS)/ txcount * 100) : 0,
- ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXJITTER)
+ stats.rxcount > (unsigned int) 100000 ? (unsigned int) (stats.rxcount)/(unsigned int) 1000 : stats.rxcount,
+ stats.rxcount > (unsigned int) 100000 ? "K":" ",
+ stats.rxploss,
+ stats.rxcount > stats.rxploss ? (stats.rxploss / stats.rxcount * 100) : 0,
+ stats.rxjitter,
+ stats.txcount > (unsigned int) 100000 ? (unsigned int) (stats.txcount)/(unsigned int) 1000 : stats.txcount,
+ stats.txcount > (unsigned int) 100000 ? "K":" ",
+ stats.txploss,
+ stats.txcount > stats.txploss ? (stats.txploss / stats.txcount * 100) : 0,
+ stats.txjitter
);
arg->numchans++;
if (p->udptl && p->t38.state == T38_LOCAL_REINVITE) {
change_t38_state(p, T38_DISABLED);
/* Try to reset RTP timers */
- ast_rtp_set_rtptimers_onhold(p->rtp);
+ //ast_rtp_set_rtptimers_onhold(p->rtp);
/* Trigger a reinvite back to audio */
transmit_reinvite_with_sdp(p, FALSE, FALSE);
{
/* Immediately stop RTP, VRTP and UDPTL as applicable */
if (p->rtp)
- ast_rtp_stop(p->rtp);
+ ast_rtp_instance_stop(p->rtp);
if (p->vrtp)
- ast_rtp_stop(p->vrtp);
+ ast_rtp_instance_stop(p->vrtp);
if (p->trtp)
- ast_rtp_stop(p->trtp);
+ ast_rtp_instance_stop(p->trtp);
if (p->udptl)
ast_udptl_stop(p->udptl);
}
build_contact(p); /* Build our contact header */
if (p->rtp) {
- ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
- ast_rtp_setdtmfcompensate(p->rtp, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
+ ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_DTMF, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
+ ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_DTMF_COMPENSATE, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
}
if (!replace_id && gotdest) { /* No matching extension found */
static int acf_channel_read(struct ast_channel *chan, const char *funcname, char *preparse, char *buf, size_t buflen)
{
struct sip_pvt *p = chan->tech_pvt;
- char *all = "", *parse = ast_strdupa(preparse);
+ char *parse = ast_strdupa(preparse);
int res = 0;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(param);
args.type = "audio";
if (!strcasecmp(args.type, "audio"))
- ast_rtp_get_peer(p->rtp, &sin);
+ ast_rtp_instance_get_remote_address(p->rtp, &sin);
else if (!strcasecmp(args.type, "video"))
- ast_rtp_get_peer(p->vrtp, &sin);
+ ast_rtp_instance_get_remote_address(p->vrtp, &sin);
else if (!strcasecmp(args.type, "text"))
- ast_rtp_get_peer(p->trtp, &sin);
+ ast_rtp_instance_get_remote_address(p->trtp, &sin);
else
return -1;
snprintf(buf, buflen, "%s:%d", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
} else if (!strcasecmp(args.param, "rtpqos")) {
- struct ast_rtp_quality qos;
- struct ast_rtp *rtp = p->rtp;
-
- memset(&qos, 0, sizeof(qos));
+ struct ast_rtp_instance *rtp = NULL;
- if (ast_strlen_zero(args.type))
+ if (ast_strlen_zero(args.type)) {
args.type = "audio";
- if (ast_strlen_zero(args.field))
- args.field = "all";
-
- if (!strcasecmp(args.type, "AUDIO")) {
- all = ast_rtp_get_quality(rtp = p->rtp, &qos, RTPQOS_SUMMARY);
- } else if (!strcasecmp(args.type, "VIDEO")) {
- all = ast_rtp_get_quality(rtp = p->vrtp, &qos, RTPQOS_SUMMARY);
- } else if (!strcasecmp(args.type, "TEXT")) {
- all = ast_rtp_get_quality(rtp = p->trtp, &qos, RTPQOS_SUMMARY);
+ }
+
+ if (!strcasecmp(args.type, "audio")) {
+ rtp = p->rtp;
+ } else if (!strcasecmp(args.type, "video")) {
+ rtp = p->vrtp;
+ } else if (!strcasecmp(args.type, "text")) {
+ rtp = p->trtp;
} else {
- return -1;
+ return -1;
}
-
- if (!strcasecmp(args.field, "local_ssrc"))
- snprintf(buf, buflen, "%u", qos.local_ssrc);
- else if (!strcasecmp(args.field, "local_lostpackets"))
- snprintf(buf, buflen, "%u", qos.local_lostpackets);
- else if (!strcasecmp(args.field, "local_jitter"))
- snprintf(buf, buflen, "%.0f", qos.local_jitter * 1000.0);
- else if (!strcasecmp(args.field, "local_count"))
- snprintf(buf, buflen, "%u", qos.local_count);
- else if (!strcasecmp(args.field, "remote_ssrc"))
- snprintf(buf, buflen, "%u", qos.remote_ssrc);
- else if (!strcasecmp(args.field, "remote_lostpackets"))
- snprintf(buf, buflen, "%u", qos.remote_lostpackets);
- else if (!strcasecmp(args.field, "remote_jitter"))
- snprintf(buf, buflen, "%.0f", qos.remote_jitter * 1000.0);
- else if (!strcasecmp(args.field, "remote_count"))
- snprintf(buf, buflen, "%u", qos.remote_count);
- else if (!strcasecmp(args.field, "rtt"))
- snprintf(buf, buflen, "%.0f", qos.rtt * 1000.0);
- else if (!strcasecmp(args.field, "all"))
- ast_copy_string(buf, all, buflen);
- else if (!ast_rtp_get_qos(rtp, args.field, buf, buflen))
- ;
- else {
- ast_log(LOG_WARNING, "Unrecognized argument '%s' to %s\n", preparse, funcname);
- return -1;
+
+ if (ast_strlen_zero(args.field) || !strcasecmp(args.field, "all")) {
+ char quality_buf[AST_MAX_USER_FIELD], *quality;
+
+ if (!(quality = ast_rtp_instance_get_quality(rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
+ return -1;
+ }
+
+ ast_copy_string(buf, quality_buf, buflen);
+ return res;
+ } else {
+ struct ast_rtp_instance_stats stats;
+
+ if (ast_rtp_instance_get_stats(rtp, &stats, AST_RTP_INSTANCE_STAT_ALL)) {
+ return -1;
+ }
+
+ if (!strcasecmp(args.field, "local_ssrc")) {
+ snprintf(buf, buflen, "%u", stats.local_ssrc);
+ } else if (!strcasecmp(args.field, "local_lostpackets")) {
+ snprintf(buf, buflen, "%u", stats.rxploss);
+ } else if (!strcasecmp(args.field, "local_jitter")) {
+ snprintf(buf, buflen, "%u", stats.rxjitter);
+ } else if (!strcasecmp(args.field, "local_count")) {
+ snprintf(buf, buflen, "%u", stats.rxcount);
+ } else if (!strcasecmp(args.field, "remote_ssrc")) {
+ snprintf(buf, buflen, "%u", stats.remote_ssrc);
+ } else if (!strcasecmp(args.field, "remote_lostpackets")) {
+ snprintf(buf, buflen, "%u", stats.txploss);
+ } else if (!strcasecmp(args.field, "remote_jitter")) {
+ snprintf(buf, buflen, "%u", stats.txjitter);
+ } else if (!strcasecmp(args.field, "remote_count")) {
+ snprintf(buf, buflen, "%u", stats.txcount);
+ } else if (!strcasecmp(args.field, "rtt")) {
+ snprintf(buf, buflen, "%u", stats.rtt);
+ } else {
+ ast_log(LOG_WARNING, "Unrecognized argument '%s' to %s\n", preparse, funcname);
+ return -1;
+ }
}
} else {
res = -1;
/* Get RTCP quality before end of call */
if (p->do_history || p->owner) {
+ char quality_buf[AST_MAX_USER_FIELD], *quality;
struct ast_channel *bridge = p->owner ? ast_bridged_channel(p->owner) : NULL;
- char *videoqos, *textqos;
- if (p->rtp) {
+ if (p->rtp && (quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
if (p->do_history) {
- char *audioqos,
- *audioqos_jitter,
- *audioqos_loss,
- *audioqos_rtt;
-
- audioqos = ast_rtp_get_quality(p->rtp, NULL, RTPQOS_SUMMARY);
- audioqos_jitter = ast_rtp_get_quality(p->rtp, NULL, RTPQOS_JITTER);
- audioqos_loss = ast_rtp_get_quality(p->rtp, NULL, RTPQOS_LOSS);
- audioqos_rtt = ast_rtp_get_quality(p->rtp, NULL, RTPQOS_RTT);
-
- append_history(p, "RTCPaudio", "Quality:%s", audioqos);
- append_history(p, "RTCPaudioJitter", "Quality:%s", audioqos_jitter);
- append_history(p, "RTCPaudioLoss", "Quality:%s", audioqos_loss);
- append_history(p, "RTCPaudioRTT", "Quality:%s", audioqos_rtt);
+ append_history(p, "RTCPaudio", "Quality:%s", quality);
+
+ if ((quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, quality_buf, sizeof(quality_buf)))) {
+ append_history(p, "RTCPaudioJitter", "Quality:%s", quality);
+ }
+ if ((quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, quality_buf, sizeof(quality_buf)))) {
+ append_history(p, "RTCPaudioLoss", "Quality:%s", quality);
+ }
+ if ((quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, quality_buf, sizeof(quality_buf)))) {
+ append_history(p, "RTCPaudioRTT", "Quality:%s", quality);
+ }
}
-
+
if (p->owner) {
- ast_rtp_set_vars(p->owner, p->rtp);
+ ast_rtp_instance_set_stats_vars(p->owner, p->rtp);
}
+
}
if (bridge) {
struct sip_pvt *q = bridge->tech_pvt;
- if (IS_SIP_TECH(bridge->tech) && q->rtp)
- ast_rtp_set_vars(bridge, q->rtp);
+ if (IS_SIP_TECH(bridge->tech) && q->rtp) {
+ ast_rtp_instance_set_stats_vars(bridge, q->rtp);
+ }
}
- if (p->vrtp) {
- videoqos = ast_rtp_get_quality(p->vrtp, NULL, RTPQOS_SUMMARY);
- if (p->do_history)
- append_history(p, "RTCPvideo", "Quality:%s", videoqos);
- if (p->owner)
- pbx_builtin_setvar_helper(p->owner, "RTPVIDEOQOS", videoqos);
+ if (p->vrtp && (quality = ast_rtp_instance_get_quality(p->vrtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
+ if (p->do_history) {
+ append_history(p, "RTCPvideo", "Quality:%s", quality);
+ }
+ if (p->owner) {
+ pbx_builtin_setvar_helper(p->owner, "RTPVIDEOQOS", quality);
+ }
}
-
- if (p->trtp) {
- textqos = ast_rtp_get_quality(p->trtp, NULL, RTPQOS_SUMMARY);
- if (p->do_history)
- append_history(p, "RTCPtext", "Quality:%s", textqos);
- if (p->owner)
- pbx_builtin_setvar_helper(p->owner, "RTPTEXTQOS", textqos);
+ if (p->trtp && (quality = ast_rtp_instance_get_quality(p->trtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
+ if (p->do_history) {
+ append_history(p, "RTCPtext", "Quality:%s", quality);
+ }
+ if (p->owner) {
+ pbx_builtin_setvar_helper(p->owner, "RTPTEXTQOS", quality);
+ }
}
}
return;
/* If we have no timers set, return now */
- if ((ast_rtp_get_rtpkeepalive(dialog->rtp) == 0) && (ast_rtp_get_rtptimeout(dialog->rtp) == 0) && (ast_rtp_get_rtpholdtimeout(dialog->rtp) == 0))
+ if (!ast_rtp_instance_get_timeout(dialog->rtp) && !ast_rtp_instance_get_hold_timeout(dialog->rtp)) {
return;
-
- /* Check AUDIO RTP keepalives */
- if (dialog->lastrtptx && ast_rtp_get_rtpkeepalive(dialog->rtp) &&
- (t > dialog->lastrtptx + ast_rtp_get_rtpkeepalive(dialog->rtp))) {
- /* Need to send an empty RTP packet */
- dialog->lastrtptx = time(NULL);
- ast_rtp_sendcng(dialog->rtp, 0);
}
/*! \todo Check video RTP keepalives
*/
/* Check AUDIO RTP timers */
- if (dialog->lastrtprx && (ast_rtp_get_rtptimeout(dialog->rtp) || ast_rtp_get_rtpholdtimeout(dialog->rtp)) &&
- (t > dialog->lastrtprx + ast_rtp_get_rtptimeout(dialog->rtp))) {
-
- /* Might be a timeout now -- see if we're on hold */
- struct sockaddr_in sin;
- ast_rtp_get_peer(dialog->rtp, &sin);
- if (!ast_test_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD) || (ast_rtp_get_rtpholdtimeout(dialog->rtp) &&
- (t > dialog->lastrtprx + ast_rtp_get_rtpholdtimeout(dialog->rtp)))) {
+ if (dialog->lastrtprx && (ast_rtp_instance_get_timeout(dialog->rtp) || ast_rtp_instance_get_hold_timeout(dialog->rtp)) && (t > dialog->lastrtprx + ast_rtp_instance_get_timeout(dialog->rtp))) {
+ if (!ast_test_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD) || (ast_rtp_instance_get_hold_timeout(dialog->rtp) && (t > dialog->lastrtprx + ast_rtp_instance_get_hold_timeout(dialog->rtp)))) {
/* Needs a hangup */
- if (ast_rtp_get_rtptimeout(dialog->rtp)) {
+ if (ast_rtp_instance_get_timeout(dialog->rtp)) {
while (dialog->owner && ast_channel_trylock(dialog->owner)) {
sip_pvt_unlock(dialog);
usleep(1);
has already been requested and we don't want to
repeatedly request hangups
*/
- ast_rtp_set_rtptimeout(dialog->rtp, 0);
- ast_rtp_set_rtpholdtimeout(dialog->rtp, 0);
+ ast_rtp_instance_set_timeout(dialog->rtp, 0);
+ ast_rtp_instance_set_hold_timeout(dialog->rtp, 0);
if (dialog->vrtp) {
- ast_rtp_set_rtptimeout(dialog->vrtp, 0);
- ast_rtp_set_rtpholdtimeout(dialog->vrtp, 0);
+ ast_rtp_instance_set_timeout(dialog->vrtp, 0);
+ ast_rtp_instance_set_hold_timeout(dialog->vrtp, 0);
}
}
}
ast_string_field_set(peer, language, default_language);
ast_string_field_set(peer, mohinterpret, default_mohinterpret);
ast_string_field_set(peer, mohsuggest, default_mohsuggest);
+ ast_string_field_set(peer, engine, default_engine);
peer->addr.sin_family = AF_INET;
peer->defaddr.sin_family = AF_INET;
peer->capability = global_capability;
ast_string_field_set(peer, mohsuggest, v->value);
} else if (!strcasecmp(v->name, "parkinglot")) {
ast_string_field_set(peer, parkinglot, v->value);
+ } else if (!strcasecmp(v->name, "rtp_engine")) {
+ ast_string_field_set(peer, engine, v->value);
} else if (!strcasecmp(v->name, "mailbox")) {
add_peer_mailboxes(peer, v->value);
} else if (!strcasecmp(v->name, "hasvoicemail")) {
ast_set_flag(&global_flags[0], SIP_DTMF_RFC2833); /*!< Default DTMF setting: RFC2833 */
ast_set_flag(&global_flags[0], SIP_NAT_RFC3581); /*!< NAT support if requested by device with rport */
ast_set_flag(&global_flags[0], SIP_CAN_REINVITE); /*!< Allow re-invites */
+ ast_copy_string(default_engine, DEFAULT_ENGINE, sizeof(default_engine));
/* Debugging settings, always default to off */
dumphistory = FALSE;
return 0;
}
-/*! \brief Returns null if we can't reinvite audio (part of RTP interface) */
-static enum ast_rtp_get_result sip_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp)
+static enum ast_rtp_glue_result sip_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
{
- struct sip_pvt *p = NULL;
- enum ast_rtp_get_result res = AST_RTP_TRY_PARTIAL;
+ struct sip_pvt *p = NULL;
+ enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_LOCAL;
- if (!(p = chan->tech_pvt))
- return AST_RTP_GET_FAILED;
-
- sip_pvt_lock(p);
- if (!(p->rtp)) {
- sip_pvt_unlock(p);
- return AST_RTP_GET_FAILED;
+ if (!(p = chan->tech_pvt)) {
+ return AST_RTP_GLUE_RESULT_FORBID;
}
- *rtp = p->rtp;
+ sip_pvt_lock(p);
+ if (!(p->rtp)) {
+ sip_pvt_unlock(p);
+ return AST_RTP_GLUE_RESULT_FORBID;
+ }
- if (ast_rtp_getnat(*rtp) && !ast_test_flag(&p->flags[0], SIP_CAN_REINVITE_NAT))
- res = AST_RTP_TRY_PARTIAL;
- else if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE))
- res = AST_RTP_TRY_NATIVE;
- else if (ast_test_flag(&global_jbconf, AST_JB_FORCED))
- res = AST_RTP_GET_FAILED;
+ ao2_ref(p->rtp, +1);
+ *instance = p->rtp;
- sip_pvt_unlock(p);
+ if (!ast_test_flag(&p->flags[0], SIP_CAN_REINVITE_NAT)) {
+ res = AST_RTP_GLUE_RESULT_LOCAL;
+ } else if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE)) {
+ res = AST_RTP_GLUE_RESULT_REMOTE;
+ } else if (ast_test_flag(&global_jbconf, AST_JB_FORCED)) {
+ res = AST_RTP_GLUE_RESULT_FORBID;
+ }
- return res;
+ sip_pvt_unlock(p);
+
+ return res;
}
-/*! \brief Returns null if we can't reinvite video (part of RTP interface) */
-static enum ast_rtp_get_result sip_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp **rtp)
+static enum ast_rtp_glue_result sip_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
{
struct sip_pvt *p = NULL;
- enum ast_rtp_get_result res = AST_RTP_TRY_PARTIAL;
-
- if (!(p = chan->tech_pvt))
- return AST_RTP_GET_FAILED;
+ enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_FORBID;
+
+ if (!(p = chan->tech_pvt)) {
+ return AST_RTP_GLUE_RESULT_FORBID;
+ }
sip_pvt_lock(p);
if (!(p->vrtp)) {
sip_pvt_unlock(p);
- return AST_RTP_GET_FAILED;
+ return AST_RTP_GLUE_RESULT_FORBID;
}
- *rtp = p->vrtp;
+ ao2_ref(p->vrtp, +1);
+ *instance = p->vrtp;
- if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE))
- res = AST_RTP_TRY_NATIVE;
+ if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE)) {
+ res = AST_RTP_GLUE_RESULT_REMOTE;
+ }
sip_pvt_unlock(p);
return res;
}
-/*! \brief Returns null if we can't reinvite text (part of RTP interface) */
-static enum ast_rtp_get_result sip_get_trtp_peer(struct ast_channel *chan, struct ast_rtp **rtp)
+static enum ast_rtp_glue_result sip_get_trtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
{
- struct sip_pvt *p = NULL;
- enum ast_rtp_get_result res = AST_RTP_TRY_PARTIAL;
-
- if (!(p = chan->tech_pvt))
- return AST_RTP_GET_FAILED;
+ struct sip_pvt *p = NULL;
+ enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_FORBID;
- sip_pvt_lock(p);
- if (!(p->trtp)) {
- sip_pvt_unlock(p);
- return AST_RTP_GET_FAILED;
- }
+ if (!(p = chan->tech_pvt)) {
+ return AST_RTP_GLUE_RESULT_FORBID;
+ }
- *rtp = p->trtp;
+ sip_pvt_lock(p);
+ if (!(p->trtp)) {
+ sip_pvt_unlock(p);
+ return AST_RTP_GLUE_RESULT_FORBID;
+ }
- if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE))
- res = AST_RTP_TRY_NATIVE;
+ ao2_ref(p->trtp, +1);
+ *instance = p->trtp;
- sip_pvt_unlock(p);
+ if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE)) {
+ res = AST_RTP_GLUE_RESULT_REMOTE;
+ }
- return res;
+ sip_pvt_unlock(p);
+
+ return res;
}
-/*! \brief Set the RTP peer for this call */
-static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active)
+static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, int codecs, int nat_active)
{
- struct sip_pvt *p;
- int changed = 0;
+ struct sip_pvt *p;
+ int changed = 0;
- p = chan->tech_pvt;
- if (!p)
- return -1;
+ p = chan->tech_pvt;
+ if (!p)
+ return -1;
/* Disable early RTP bridge */
if (chan->_state != AST_STATE_UP && !sip_cfg.directrtpsetup) /* We are in early state */
return 0;
- sip_pvt_lock(p);
- if (p->alreadygone) {
- /* If we're destroyed, don't bother */
- sip_pvt_unlock(p);
- return 0;
- }
+ sip_pvt_lock(p);
+ if (p->alreadygone) {
+ /* If we're destroyed, don't bother */
+ sip_pvt_unlock(p);
+ return 0;
+ }
- /* if this peer cannot handle reinvites of the media stream to devices
- that are known to be behind a NAT, then stop the process now
+ /* if this peer cannot handle reinvites of the media stream to devices
+ that are known to be behind a NAT, then stop the process now
*/
- if (nat_active && !ast_test_flag(&p->flags[0], SIP_CAN_REINVITE_NAT)) {
- sip_pvt_unlock(p);
- return 0;
- }
+ if (nat_active && !ast_test_flag(&p->flags[0], SIP_CAN_REINVITE_NAT)) {
+ sip_pvt_unlock(p);
+ return 0;
+ }
- if (rtp) {
- changed |= ast_rtp_get_peer(rtp, &p->redirip);
- } else if (p->redirip.sin_addr.s_addr || ntohs(p->redirip.sin_port) != 0) {
- memset(&p->redirip, 0, sizeof(p->redirip));
- changed = 1;
- }
- if (vrtp) {
- changed |= ast_rtp_get_peer(vrtp, &p->vredirip);
- } else if (p->vredirip.sin_addr.s_addr || ntohs(p->vredirip.sin_port) != 0) {
- memset(&p->vredirip, 0, sizeof(p->vredirip));
- changed = 1;
- }
- if (trtp) {
- changed |= ast_rtp_get_peer(trtp, &p->tredirip);
- } else if (p->tredirip.sin_addr.s_addr || ntohs(p->tredirip.sin_port) != 0) {
- memset(&p->tredirip, 0, sizeof(p->tredirip));
- changed = 1;
- }
- if (codecs && (p->redircodecs != codecs)) {
- p->redircodecs = codecs;
- changed = 1;
- }
- if (changed && !ast_test_flag(&p->flags[0], SIP_GOTREFER) && !ast_test_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER)) {
- if (chan->_state != AST_STATE_UP) { /* We are in early state */
- if (p->do_history)
- append_history(p, "ExtInv", "Initial invite sent with remote bridge proposal.");
- ast_debug(1, "Early remote bridge setting SIP '%s' - Sending media to %s\n", p->callid, ast_inet_ntoa(rtp ? p->redirip.sin_addr : p->ourip.sin_addr));
- } else if (!p->pendinginvite) { /* We are up, and have no outstanding invite */
- ast_debug(3, "Sending reinvite on SIP '%s' - It's audio soon redirected to IP %s\n", p->callid, ast_inet_ntoa(rtp ? p->redirip.sin_addr : p->ourip.sin_addr));
- transmit_reinvite_with_sdp(p, FALSE, FALSE);
- } else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) {
- ast_debug(3, "Deferring reinvite on SIP '%s' - It's audio will be redirected to IP %s\n", p->callid, ast_inet_ntoa(rtp ? p->redirip.sin_addr : p->ourip.sin_addr));
- /* We have a pending Invite. Send re-invite when we're done with the invite */
- ast_set_flag(&p->flags[0], SIP_NEEDREINVITE);
- }
- }
- /* Reset lastrtprx timer */
- p->lastrtprx = p->lastrtptx = time(NULL);
- sip_pvt_unlock(p);
- return 0;
+ if (instance) {
+ changed |= ast_rtp_instance_get_remote_address(instance, &p->redirip);
+ } else if (p->redirip.sin_addr.s_addr || ntohs(p->redirip.sin_port) != 0) {
+ memset(&p->redirip, 0, sizeof(p->redirip));
+ changed = 1;
+ }
+ if (vinstance) {
+ changed |= ast_rtp_instance_get_remote_address(vinstance, &p->vredirip);
+ } else if (p->vredirip.sin_addr.s_addr || ntohs(p->vredirip.sin_port) != 0) {
+ memset(&p->vredirip, 0, sizeof(p->vredirip));
+ changed = 1;
+ }
+ if (tinstance) {
+ changed |= ast_rtp_instance_get_remote_address(tinstance, &p->tredirip);
+ } else if (p->tredirip.sin_addr.s_addr || ntohs(p->tredirip.sin_port) != 0) {
+ memset(&p->tredirip, 0, sizeof(p->tredirip));
+ changed = 1;
+ }
+ if (codecs && (p->redircodecs != codecs)) {
+ p->redircodecs = codecs;
+ changed = 1;
+ }
+ if (changed && !ast_test_flag(&p->flags[0], SIP_GOTREFER) && !ast_test_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER)) {
+ if (chan->_state != AST_STATE_UP) { /* We are in early state */
+ if (p->do_history)
+ append_history(p, "ExtInv", "Initial invite sent with remote bridge proposal.");
+ ast_debug(1, "Early remote bridge setting SIP '%s' - Sending media to %s\n", p->callid, ast_inet_ntoa(instance ? p->redirip.sin_addr : p->ourip.sin_addr));
+ } else if (!p->pendinginvite) { /* We are up, and have no outstanding invite */
+ ast_debug(3, "Sending reinvite on SIP '%s' - It's audio soon redirected to IP %s\n", p->callid, ast_inet_ntoa(instance ? p->redirip.sin_addr : p->ourip.sin_addr));
+ transmit_reinvite_with_sdp(p, FALSE, FALSE);
+ } else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) {
+ ast_debug(3, "Deferring reinvite on SIP '%s' - It's audio will be redirected to IP %s\n", p->callid, ast_inet_ntoa(instance ? p->redirip.sin_addr : p->ourip.sin_addr));
+ /* We have a pending Invite. Send re-invite when we're done with the invite */
+ ast_set_flag(&p->flags[0], SIP_NEEDREINVITE);
+ }
+ }
+ /* Reset lastrtprx timer */
+ p->lastrtprx = p->lastrtptx = time(NULL);
+ sip_pvt_unlock(p);
+ return 0;
}
+static int sip_get_codec(struct ast_channel *chan)
+{
+ struct sip_pvt *p = chan->tech_pvt;
+ return p->peercapability ? p->peercapability : p->capability;
+}
+
+static struct ast_rtp_glue sip_rtp_glue = {
+ .type = "SIP",
+ .get_rtp_info = sip_get_rtp_peer,
+ .get_vrtp_info = sip_get_vrtp_peer,
+ .get_trtp_info = sip_get_trtp_peer,
+ .update_peer = sip_set_rtp_peer,
+ .get_codec = sip_get_codec,
+};
+
static char *app_dtmfmode = "SIPDtmfMode";
static char *app_sipaddheader = "SIPAddHeader";
static char *app_sipremoveheader = "SIPRemoveHeader";
} else
ast_log(LOG_WARNING, "I don't know about this dtmf mode: %s\n", mode);
if (p->rtp)
- ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
+ ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_DTMF, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
if (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) {
if (!p->vad) {
p->vad = ast_dsp_new();
return 0;
}
-/*! \brief Return SIP UA's codec (part of the RTP interface) */
-static int sip_get_codec(struct ast_channel *chan)
-{
- struct sip_pvt *p = chan->tech_pvt;
- return p->jointcapability ? p->jointcapability : p->capability;
-}
-
/*! \brief Send a poke to all known peers */
static void sip_poke_all_peers(void)
{
/* Register all CLI functions for SIP */
ast_cli_register_multiple(cli_sip, ARRAY_LEN(cli_sip));
- /* Tell the RTP subdriver that we're here */
- ast_rtp_proto_register(&sip_rtp);
-
/* Tell the UDPTL subdriver that we're here */
ast_udptl_proto_register(&sip_udptl);
+ /* Tell the RTP engine about our RTP glue */
+ ast_rtp_glue_register(&sip_rtp_glue);
+
/* Register dialplan applications */
ast_register_application_xml(app_dtmfmode, sip_dtmfmode);
ast_register_application_xml(app_sipaddheader, sip_addheader);
/* Unregister CLI commands */
ast_cli_unregister_multiple(cli_sip, ARRAY_LEN(cli_sip));
- /* Disconnect from the RTP subsystem */
- ast_rtp_proto_unregister(&sip_rtp);
-
/* Disconnect from UDPTL */
ast_udptl_proto_unregister(&sip_udptl);
+ /* Disconnect from RTP engine */
+ ast_rtp_glue_unregister(&sip_rtp_glue);
+
/* Unregister AMI actions */
ast_manager_unregister("SIPpeers");
ast_manager_unregister("SIPshowpeer");
#include "asterisk/pbx.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
-#include "asterisk/rtp.h"
+#include "asterisk/rtp_engine.h"
#include "asterisk/netsock.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
struct skinny_subchannel {
ast_mutex_t lock;
struct ast_channel *owner;
- struct ast_rtp *rtp;
- struct ast_rtp *vrtp;
+ struct ast_rtp_instance *rtp;
+ struct ast_rtp_instance *vrtp;
unsigned int callid;
/* time_t lastouttime; */ /* Unused */
int progress;
.fixup = skinny_fixup,
.send_digit_begin = skinny_senddigit_begin,
.send_digit_end = skinny_senddigit_end,
- .bridge = ast_rtp_bridge,
+ .bridge = ast_rtp_instance_bridge,
};
static int skinny_extensionstate_cb(char *context, char* exten, int state, void *data);
/* I do not believe skinny can deal with video.
Anyone know differently? */
/* Yes, it can. Currently 7985 and Cisco VT Advantage do video. */
-static enum ast_rtp_get_result skinny_get_vrtp_peer(struct ast_channel *c, struct ast_rtp **rtp)
+static enum ast_rtp_glue_result skinny_get_vrtp_peer(struct ast_channel *c, struct ast_rtp_instance **instance)
{
struct skinny_subchannel *sub = NULL;
if (!(sub = c->tech_pvt) || !(sub->vrtp))
- return AST_RTP_GET_FAILED;
+ return AST_RTP_GLUE_RESULT_FORBID;
- *rtp = sub->vrtp;
+ ao2_ref(sub->vrtp, +1);
+ *instance = sub->vrtp;
- return AST_RTP_TRY_NATIVE;
+ return AST_RTP_GLUE_RESULT_REMOTE;
}
-static enum ast_rtp_get_result skinny_get_rtp_peer(struct ast_channel *c, struct ast_rtp **rtp)
+static enum ast_rtp_glue_result skinny_get_rtp_peer(struct ast_channel *c, struct ast_rtp_instance **instance)
{
struct skinny_subchannel *sub = NULL;
struct skinny_line *l;
- enum ast_rtp_get_result res = AST_RTP_TRY_NATIVE;
+ enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_REMOTE;
if (skinnydebug)
ast_verb(1, "skinny_get_rtp_peer() Channel = %s\n", c->name);
if (!(sub = c->tech_pvt))
- return AST_RTP_GET_FAILED;
+ return AST_RTP_GLUE_RESULT_FORBID;
ast_mutex_lock(&sub->lock);
if (!(sub->rtp)){
ast_mutex_unlock(&sub->lock);
- return AST_RTP_GET_FAILED;
+ return AST_RTP_GLUE_RESULT_FORBID;
}
-
- *rtp = sub->rtp;
+
+ ao2_ref(sub->rtp, +1);
+ *instance = sub->rtp;
l = sub->parent;
if (!l->canreinvite || l->nat){
- res = AST_RTP_TRY_PARTIAL;
+ res = AST_RTP_GLUE_RESULT_LOCAL;
if (skinnydebug)
- ast_verb(1, "skinny_get_rtp_peer() Using AST_RTP_TRY_PARTIAL \n");
+ ast_verb(1, "skinny_get_rtp_peer() Using AST_RTP_GLUE_RESULT_LOCAL \n");
}
ast_mutex_unlock(&sub->lock);
}
-static int skinny_set_rtp_peer(struct ast_channel *c, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active)
+static int skinny_set_rtp_peer(struct ast_channel *c, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, int codecs, int nat_active)
{
struct skinny_subchannel *sub;
struct skinny_line *l;
s = d->session;
if (rtp){
- ast_rtp_get_peer(rtp, &them);
+ ast_rtp_instance_get_remote_address(rtp, &them);
/* Shutdown any early-media or previous media on re-invite */
if (!(req = req_alloc(sizeof(struct stop_media_transmission_message), STOP_MEDIA_TRANSMISSION_MESSAGE)))
req->data.startmedia.conferenceId = htolel(sub->callid);
req->data.startmedia.passThruPartyId = htolel(sub->callid);
if (!(l->canreinvite) || (l->nat)){
- ast_rtp_get_us(rtp, &us);
+ ast_rtp_instance_get_local_address(rtp, &us);
req->data.startmedia.remoteIp = htolel(d->ourip.s_addr);
req->data.startmedia.remotePort = htolel(ntohs(us.sin_port));
} else {
return 0;
}
-static struct ast_rtp_protocol skinny_rtp = {
+static struct ast_rtp_glue skinny_rtp_glue = {
.type = "Skinny",
.get_rtp_info = skinny_get_rtp_peer,
.get_vrtp_info = skinny_get_vrtp_peer,
- .set_rtp_peer = skinny_set_rtp_peer,
+ .update_peer = skinny_set_rtp_peer,
};
static char *handle_skinny_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
ast_mutex_lock(&sub->lock);
/* Allocate the RTP */
- sub->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
+ sub->rtp = ast_rtp_instance_new(NULL, sched, &bindaddr, NULL);
if (hasvideo)
- sub->vrtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
-
+ sub->vrtp = ast_rtp_instance_new(NULL, sched, &bindaddr, NULL);
+
+ if (sub->rtp) {
+ ast_rtp_instance_set_prop(sub->rtp, AST_RTP_PROPERTY_RTCP, 1);
+ }
+ if (sub->vrtp) {
+ ast_rtp_instance_set_prop(sub->vrtp, AST_RTP_PROPERTY_RTCP, 1);
+ }
+
if (sub->rtp && sub->owner) {
- ast_channel_set_fd(sub->owner, 0, ast_rtp_fd(sub->rtp));
- ast_channel_set_fd(sub->owner, 1, ast_rtcp_fd(sub->rtp));
+ ast_channel_set_fd(sub->owner, 0, ast_rtp_instance_fd(sub->rtp, 0));
+ ast_channel_set_fd(sub->owner, 1, ast_rtp_instance_fd(sub->rtp, 1));
}
if (hasvideo && sub->vrtp && sub->owner) {
- ast_channel_set_fd(sub->owner, 2, ast_rtp_fd(sub->vrtp));
- ast_channel_set_fd(sub->owner, 3, ast_rtcp_fd(sub->vrtp));
+ ast_channel_set_fd(sub->owner, 2, ast_rtp_instance_fd(sub->vrtp, 0));
+ ast_channel_set_fd(sub->owner, 3, ast_rtp_instance_fd(sub->vrtp, 1));
}
if (sub->rtp) {
- ast_rtp_setqos(sub->rtp, qos.tos_audio, qos.cos_audio, "Skinny RTP");
- ast_rtp_setnat(sub->rtp, l->nat);
+ ast_rtp_instance_set_qos(sub->rtp, qos.tos_audio, qos.cos_audio, "Skinny RTP");
+ ast_rtp_instance_set_prop(sub->rtp, AST_RTP_PROPERTY_NAT, l->nat);
}
if (sub->vrtp) {
- ast_rtp_setqos(sub->vrtp, qos.tos_video, qos.cos_video, "Skinny VRTP");
- ast_rtp_setnat(sub->vrtp, l->nat);
+ ast_rtp_instance_set_qos(sub->vrtp, qos.tos_video, qos.cos_video, "Skinny VRTP");
+ ast_rtp_instance_set_prop(sub->vrtp, AST_RTP_PROPERTY_NAT, l->nat);
}
/* Set Frame packetization */
if (sub->rtp)
- ast_rtp_codec_setpref(sub->rtp, &l->prefs);
+ ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(sub->rtp), sub->rtp, &l->prefs);
/* Create the RTP connection */
transmit_connect(d, sub);
sub->alreadygone = 0;
sub->outgoing = 0;
if (sub->rtp) {
- ast_rtp_destroy(sub->rtp);
+ ast_rtp_instance_destroy(sub->rtp);
sub->rtp = NULL;
}
ast_mutex_unlock(&sub->lock);
switch(ast->fdno) {
case 0:
- f = ast_rtp_read(sub->rtp); /* RTP Audio */
+ f = ast_rtp_instance_read(sub->rtp, 0); /* RTP Audio */
break;
case 1:
- f = ast_rtcp_read(sub->rtp); /* RTCP Control Channel */
+ f = ast_rtp_instance_read(sub->rtp, 1); /* RTCP Control Channel */
break;
case 2:
- f = ast_rtp_read(sub->vrtp); /* RTP Video */
+ f = ast_rtp_instance_read(sub->vrtp, 0); /* RTP Video */
break;
case 3:
- f = ast_rtcp_read(sub->vrtp); /* RTCP Control Channel for video */
+ f = ast_rtp_instance_read(sub->vrtp, 1); /* RTCP Control Channel for video */
break;
#if 0
case 5:
if (sub) {
ast_mutex_lock(&sub->lock);
if (sub->rtp) {
- res = ast_rtp_write(sub->rtp, frame);
+ res = ast_rtp_instance_write(sub->rtp, frame);
}
ast_mutex_unlock(&sub->lock);
}
case AST_CONTROL_PROCEEDING:
break;
case AST_CONTROL_SRCUPDATE:
- ast_rtp_new_source(sub->rtp);
+ ast_rtp_instance_new_source(sub->rtp);
break;
default:
ast_log(LOG_WARNING, "Don't know how to indicate condition %d\n", ind);
if (skinnydebug)
ast_verb(1, "skinny_new: tmp->nativeformats=%d fmt=%d\n", tmp->nativeformats, fmt);
if (sub->rtp) {
- ast_channel_set_fd(tmp, 0, ast_rtp_fd(sub->rtp));
+ ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(sub->rtp, 0));
}
if (state == AST_STATE_RING) {
tmp->rings = 1;
l = sub->parent;
if (sub->rtp) {
- ast_rtp_set_peer(sub->rtp, &sin);
- ast_rtp_get_us(sub->rtp, &us);
+ ast_rtp_instance_set_remote_address(sub->rtp, &sin);
+ ast_rtp_instance_get_local_address(sub->rtp, &us);
} else {
ast_log(LOG_ERROR, "No RTP structure, this is very bad\n");
return 0;
return -1;
}
- ast_rtp_proto_register(&skinny_rtp);
+ ast_rtp_glue_register(&skinny_rtp_glue);
ast_cli_register_multiple(cli_skinny, ARRAY_LEN(cli_skinny));
ast_manager_register2("SKINNYdevices", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, manager_skinny_show_devices,
struct skinny_subchannel *sub;
struct ast_context *con;
- ast_rtp_proto_unregister(&skinny_rtp);
+ ast_rtp_glue_unregister(&skinny_rtp_glue);
ast_channel_unregister(&skinny_tech);
ast_cli_unregister_multiple(cli_skinny, ARRAY_LEN(cli_skinny));
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/event.h"
-#include "asterisk/rtp.h"
+#include "asterisk/rtp_engine.h"
#include "asterisk/netsock.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
/*! Unistim line */
struct unistim_line *parent;
/*! RTP handle */
- struct ast_rtp *rtp;
+ struct ast_rtp_instance *rtp;
int alreadygone;
char ringvolume;
char ringstyle;
.send_digit_begin = unistim_senddigit_begin,
.send_digit_end = unistim_senddigit_end,
.send_text = unistim_sendtext,
-/* .bridge = ast_rtp_bridge, */
+ .bridge = ast_rtp_instance_bridge,
};
static void display_last_error(const char *sz_msg)
static void swap_subs(struct unistim_line *p, int a, int b)
{
/* struct ast_channel *towner; */
- struct ast_rtp *rtp;
+ struct ast_rtp_instance *rtp;
int fds;
if (unistimdebug)
/* Allocate the RTP */
if (unistimdebug)
ast_verb(0, "Starting RTP. Bind on %s\n", ast_inet_ntoa(sout.sin_addr));
- sub->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, sout.sin_addr);
+ sub->rtp = ast_rtp_instance_new(NULL, sched, &sout, NULL);
if (!sub->rtp) {
ast_log(LOG_WARNING, "Unable to create RTP session: %s binaddr=%s\n",
strerror(errno), ast_inet_ntoa(sout.sin_addr));
ast_mutex_unlock(&sub->lock);
return;
}
- if (sub->rtp && sub->owner) {
- sub->owner->fds[0] = ast_rtp_fd(sub->rtp);
- sub->owner->fds[1] = ast_rtcp_fd(sub->rtp);
- }
- if (sub->rtp) {
- ast_rtp_setqos(sub->rtp, qos.tos_audio, qos.cos_audio, "UNISTIM RTP");
- ast_rtp_setnat(sub->rtp, sub->parent->parent->nat);
+ ast_rtp_instance_set_prop(sub->rtp, AST_RTP_PROPERTY_RTCP, 1);
+ if (sub->owner) {
+ sub->owner->fds[0] = ast_rtp_instance_fd(sub->rtp, 0);
+ sub->owner->fds[1] = ast_rtp_instance_fd(sub->rtp, 1);
}
+ ast_rtp_instance_set_qos(sub->rtp, qos.tos_audio, qos.cos_audio, "UNISTIM RTP");
+ ast_rtp_instance_set_prop(sub->rtp, AST_RTP_PROPERTY_NAT, sub->parent->parent->nat);
/* Create the RTP connection */
- ast_rtp_get_us(sub->rtp, &us);
+ ast_rtp_instance_get_local_address(sub->rtp, &us);
sin.sin_family = AF_INET;
/* Setting up RTP for our side */
memcpy(&sin.sin_addr, &sub->parent->parent->session->sin.sin_addr,
sizeof(sin.sin_addr));
sin.sin_port = htons(sub->parent->parent->rtp_port);
- ast_rtp_set_peer(sub->rtp, &sin);
+ ast_rtp_instance_set_remote_address(sub->rtp, &sin);
if (!(sub->owner->nativeformats & sub->owner->readformat)) {
int fmt;
fmt = ast_best_codec(sub->owner->nativeformats);
sub->owner->readformat = fmt;
sub->owner->writeformat = fmt;
}
- codec = ast_rtp_lookup_code(sub->rtp, 1, sub->owner->readformat);
+ codec = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(sub->rtp), 1, sub->owner->readformat);
/* Setting up RTP of the phone */
if (public_ip.sin_family == 0) /* NAT IP override ? */
memcpy(&public, &us, sizeof(public)); /* No defined, using IP from recvmsg */
if (sub->rtp) {
if (unistimdebug)
ast_verb(0, "Destroying RTP session\n");
- ast_rtp_destroy(sub->rtp);
+ ast_rtp_instance_destroy(sub->rtp);
sub->rtp = NULL;
}
return 0;
if (sub->rtp) {
if (unistimdebug)
ast_verb(0, "Destroying RTP session\n");
- ast_rtp_destroy(sub->rtp);
+ ast_rtp_instance_destroy(sub->rtp);
sub->rtp = NULL;
}
return 0;
if (sub->rtp) {
if (unistimdebug)
ast_verb(0, "Destroying RTP session\n");
- ast_rtp_destroy(sub->rtp);
+ ast_rtp_instance_destroy(sub->rtp);
sub->rtp = NULL;
} else if (unistimdebug)
ast_verb(0, "No RTP session to destroy\n");
switch (ast->fdno) {
case 0:
- f = ast_rtp_read(sub->rtp); /* RTP Audio */
+ f = ast_rtp_instance_read(sub->rtp, 0); /* RTP Audio */
break;
case 1:
- f = ast_rtcp_read(sub->rtp); /* RTCP Control Channel */
+ f = ast_rtp_instance_read(sub->rtp, 1); /* RTCP Control Channel */
break;
default:
f = &ast_null_frame;
if (sub) {
ast_mutex_lock(&sub->lock);
if (sub->rtp) {
- res = ast_rtp_write(sub->rtp, frame);
+ res = ast_rtp_instance_write(sub->rtp, frame);
}
ast_mutex_unlock(&sub->lock);
}
if ((sub->rtp) && (sub->subtype == 0)) {
if (unistimdebug)
ast_verb(0, "New unistim channel with a previous rtp handle ?\n");
- tmp->fds[0] = ast_rtp_fd(sub->rtp);
- tmp->fds[1] = ast_rtcp_fd(sub->rtp);
+ tmp->fds[0] = ast_rtp_instance_fd(sub->rtp, 0);
+ tmp->fds[1] = ast_rtp_instance_fd(sub->rtp, 1);
}
if (sub->rtp)
ast_jb_configure(tmp, &global_jbconf);
return 0;
}
-static enum ast_rtp_get_result unistim_get_vrtp_peer(struct ast_channel *chan,
- struct ast_rtp **rtp)
-{
- return AST_RTP_TRY_NATIVE;
-}
-
-static enum ast_rtp_get_result unistim_get_rtp_peer(struct ast_channel *chan,
- struct ast_rtp **rtp)
-{
- struct unistim_subchannel *sub;
- enum ast_rtp_get_result res = AST_RTP_GET_FAILED;
-
- if (unistimdebug)
- ast_verb(0, "unistim_get_rtp_peer called\n");
-
- sub = chan->tech_pvt;
- if (sub && sub->rtp) {
- *rtp = sub->rtp;
- res = AST_RTP_TRY_NATIVE;
- }
-
- return res;
-}
-
-static int unistim_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp,
- struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active)
+static enum ast_rtp_glue_result unistim_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
{
- struct unistim_subchannel *sub;
-
- if (unistimdebug)
- ast_verb(0, "unistim_set_rtp_peer called\n");
-
- sub = chan->tech_pvt;
+ struct unistim_subchannel *sub = chan->tech_pvt;
- if (sub)
- return 0;
+ ao2_ref(sub->rtp, +1);
+ *instance = sub->rtp;
- return -1;
+ return AST_RTP_GLUE_RESULT_LOCAL;
}
-static struct ast_rtp_protocol unistim_rtp = {
+static struct ast_rtp_glue unistim_rtp_glue = {
.type = channel_type,
.get_rtp_info = unistim_get_rtp_peer,
- .get_vrtp_info = unistim_get_vrtp_peer,
- .set_rtp_peer = unistim_set_rtp_peer,
};
/*--- load_module: PBX load module - initialization ---*/
goto chanreg_failed;
}
- ast_rtp_proto_register(&unistim_rtp);
+ ast_rtp_glue_register(&unistim_rtp_glue);
ast_cli_register_multiple(unistim_cli, ARRAY_LEN(unistim_cli));
ast_cli_unregister_multiple(unistim_cli, ARRAY_LEN(unistim_cli));
ast_channel_unregister(&unistim_tech);
- ast_rtp_proto_unregister(&unistim_rtp);
+ ast_rtp_glue_unregister(&unistim_rtp_glue);
ast_mutex_lock(&monlock);
if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) {
;contactpermit=172.16.0.0/255.255.0.0 ; restrict at what IPs your users may
; register their phones.
+;engine=asterisk ; RTP engine to use when communicating with the device
+
;
; If regcontext is specified, Asterisk will dynamically create and destroy a
; NoOp priority 1 extension for a given peer who registers or unregisters with
int ast_timing_init(void); /*!< Provided by timing.c */
int ast_indications_init(void); /*!< Provided by indications.c */
int ast_indications_reload(void);/*!< Provided by indications.c */
+void ast_stun_init(void); /*!< Provided by stun.c */
/*!
* \brief Reload asterisk modules.
+++ /dev/null
-/*
- * 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 rtp.h
- * \brief Supports RTP and RTCP with Symmetric RTP support for NAT traversal.
- *
- * RTP is defined in RFC 3550.
- */
-
-#ifndef _ASTERISK_RTP_H
-#define _ASTERISK_RTP_H
-
-#include "asterisk/network.h"
-
-#include "asterisk/frame.h"
-#include "asterisk/io.h"
-#include "asterisk/sched.h"
-#include "asterisk/channel.h"
-#include "asterisk/linkedlists.h"
-
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-/* Codes for RTP-specific data - not defined by our AST_FORMAT codes */
-/*! DTMF (RFC2833) */
-#define AST_RTP_DTMF (1 << 0)
-/*! 'Comfort Noise' (RFC3389) */
-#define AST_RTP_CN (1 << 1)
-/*! DTMF (Cisco Proprietary) */
-#define AST_RTP_CISCO_DTMF (1 << 2)
-/*! Maximum RTP-specific code */
-#define AST_RTP_MAX AST_RTP_CISCO_DTMF
-
-/*! Maxmum number of payload defintions for a RTP session */
-#define MAX_RTP_PT 256
-
-/*! T.140 Redundancy Maxium number of generations */
-#define RED_MAX_GENERATION 5
-
-#define FLAG_3389_WARNING (1 << 0)
-
-enum ast_rtp_options {
- AST_RTP_OPT_G726_NONSTANDARD = (1 << 0),
-};
-
-enum ast_rtp_get_result {
- /*! Failed to find the RTP structure */
- AST_RTP_GET_FAILED = 0,
- /*! RTP structure exists but true native bridge can not occur so try partial */
- AST_RTP_TRY_PARTIAL,
- /*! RTP structure exists and native bridge can occur */
- AST_RTP_TRY_NATIVE,
-};
-
-/*! \brief Variables used in ast_rtcp_get function */
-enum ast_rtp_qos_vars {
- AST_RTP_TXCOUNT,
- AST_RTP_RXCOUNT,
- AST_RTP_TXJITTER,
- AST_RTP_RXJITTER,
- AST_RTP_RXPLOSS,
- AST_RTP_TXPLOSS,
- AST_RTP_RTT
-};
-
-struct ast_rtp;
-/*! T.140 Redundancy structure*/
-struct rtp_red;
-
-/*! \brief The value of each payload format mapping: */
-struct rtpPayloadType {
- int isAstFormat; /*!< whether the following code is an AST_FORMAT */
- int code;
-};
-
-/*! \brief This is the structure that binds a channel (SIP/Jingle/H.323) to the RTP subsystem
-*/
-struct ast_rtp_protocol {
- /*! Get RTP struct, or NULL if unwilling to transfer */
- enum ast_rtp_get_result (* const get_rtp_info)(struct ast_channel *chan, struct ast_rtp **rtp);
- /*! Get RTP struct, or NULL if unwilling to transfer */
- enum ast_rtp_get_result (* const get_vrtp_info)(struct ast_channel *chan, struct ast_rtp **rtp);
- /*! Get RTP struct, or NULL if unwilling to transfer */
- enum ast_rtp_get_result (* const get_trtp_info)(struct ast_channel *chan, struct ast_rtp **rtp);
- /*! Set RTP peer */
- int (* const set_rtp_peer)(struct ast_channel *chan, struct ast_rtp *peer, struct ast_rtp *vpeer, struct ast_rtp *tpeer, int codecs, int nat_active);
- int (* const get_codec)(struct ast_channel *chan);
- const char * const type;
- AST_LIST_ENTRY(ast_rtp_protocol) list;
-};
-
-enum ast_rtp_quality_type {
- RTPQOS_SUMMARY = 0,
- RTPQOS_JITTER,
- RTPQOS_LOSS,
- RTPQOS_RTT
-};
-
-/*! \brief RTCP quality report storage */
-struct ast_rtp_quality {
- unsigned int local_ssrc; /*!< Our SSRC */
- unsigned int local_lostpackets; /*!< Our lost packets */
- double local_jitter; /*!< Our calculated jitter */
- unsigned int local_count; /*!< Number of received packets */
- unsigned int remote_ssrc; /*!< Their SSRC */
- unsigned int remote_lostpackets; /*!< Their lost packets */
- double remote_jitter; /*!< Their reported jitter */
- unsigned int remote_count; /*!< Number of transmitted packets */
- double rtt; /*!< Round trip time */
-};
-
-/*! RTP callback structure */
-typedef int (*ast_rtp_callback)(struct ast_rtp *rtp, struct ast_frame *f, void *data);
-
-/*!
- * \brief Get the amount of space required to hold an RTP session
- * \return number of bytes required
- */
-size_t ast_rtp_alloc_size(void);
-
-/*!
- * \brief Initializate a RTP session.
- *
- * \param sched
- * \param io
- * \param rtcpenable
- * \param callbackmode
- * \return A representation (structure) of an RTP session.
- */
-struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode);
-
-/*!
- * \brief Initializate a RTP session using an in_addr structure.
- *
- * This fuction gets called by ast_rtp_new().
- *
- * \param sched
- * \param io
- * \param rtcpenable
- * \param callbackmode
- * \param in
- * \return A representation (structure) of an RTP session.
- */
-struct ast_rtp *ast_rtp_new_with_bindaddr(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode, struct in_addr in);
-
-void ast_rtp_set_peer(struct ast_rtp *rtp, struct sockaddr_in *them);
-
-/* Copies from rtp to them and returns 1 if there was a change or 0 if it was already the same */
-int ast_rtp_get_peer(struct ast_rtp *rtp, struct sockaddr_in *them);
-
-void ast_rtp_get_us(struct ast_rtp *rtp, struct sockaddr_in *us);
-
-struct ast_rtp *ast_rtp_get_bridged(struct ast_rtp *rtp);
-
-/*! Destroy RTP session */
-void ast_rtp_destroy(struct ast_rtp *rtp);
-
-void ast_rtp_reset(struct ast_rtp *rtp);
-
-/*! Stop RTP session, do not destroy structure */
-void ast_rtp_stop(struct ast_rtp *rtp);
-
-void ast_rtp_set_callback(struct ast_rtp *rtp, ast_rtp_callback callback);
-
-void ast_rtp_set_data(struct ast_rtp *rtp, void *data);
-
-int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *f);
-
-struct ast_frame *ast_rtp_read(struct ast_rtp *rtp);
-
-struct ast_frame *ast_rtcp_read(struct ast_rtp *rtp);
-
-int ast_rtp_fd(struct ast_rtp *rtp);
-
-int ast_rtcp_fd(struct ast_rtp *rtp);
-
-int ast_rtp_senddigit_begin(struct ast_rtp *rtp, char digit);
-
-int ast_rtp_senddigit_end(struct ast_rtp *rtp, char digit);
-
-int ast_rtp_sendcng(struct ast_rtp *rtp, int level);
-
-int ast_rtp_setqos(struct ast_rtp *rtp, int tos, int cos, char *desc);
-
-void ast_rtp_new_source(struct ast_rtp *rtp);
-
-/*! \brief Setting RTP payload types from lines in a SDP description: */
-void ast_rtp_pt_clear(struct ast_rtp* rtp);
-/*! \brief Set payload types to defaults */
-void ast_rtp_pt_default(struct ast_rtp* rtp);
-
-/*! \brief Copy payload types between RTP structures */
-void ast_rtp_pt_copy(struct ast_rtp *dest, struct ast_rtp *src);
-
-/*! \brief Activate payload type */
-void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt);
-
-/*! \brief clear payload type */
-void ast_rtp_unset_m_type(struct ast_rtp* rtp, int pt);
-
-/*! \brief Set payload type to a known MIME media type for a codec
- *
- * \param rtp RTP structure to modify
- * \param pt Payload type entry to modify
- * \param mimeType top-level MIME type of media stream (typically "audio", "video", "text", etc.)
- * \param mimeSubtype MIME subtype of media stream (typically a codec name)
- * \param options Zero or more flags from the ast_rtp_options enum
- *
- * This function 'fills in' an entry in the list of possible formats for
- * a media stream associated with an RTP structure.
- *
- * \retval 0 on success
- * \retval -1 if the payload type is out of range
- * \retval -2 if the mimeType/mimeSubtype combination was not found
- */
-int ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
- char *mimeType, char *mimeSubtype,
- enum ast_rtp_options options);
-
-/*! \brief Set payload type to a known MIME media type for a codec with a specific sample rate
- *
- * \param rtp RTP structure to modify
- * \param pt Payload type entry to modify
- * \param mimeType top-level MIME type of media stream (typically "audio", "video", "text", etc.)
- * \param mimeSubtype MIME subtype of media stream (typically a codec name)
- * \param options Zero or more flags from the ast_rtp_options enum
- * \param sample_rate The sample rate of the media stream
- *
- * This function 'fills in' an entry in the list of possible formats for
- * a media stream associated with an RTP structure.
- *
- * \retval 0 on success
- * \retval -1 if the payload type is out of range
- * \retval -2 if the mimeType/mimeSubtype combination was not found
- */
-int ast_rtp_set_rtpmap_type_rate(struct ast_rtp* rtp, int pt,
- char *mimeType, char *mimeSubtype,
- enum ast_rtp_options options,
- unsigned int sample_rate);
-
-/*! \brief Mapping between RTP payload format codes and Asterisk codes: */
-struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt);
-int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code);
-
-void ast_rtp_get_current_formats(struct ast_rtp* rtp,
- int* astFormats, int* nonAstFormats);
-
-/*! \brief Mapping an Asterisk code into a MIME subtype (string): */
-const char *ast_rtp_lookup_mime_subtype(int isAstFormat, int code,
- enum ast_rtp_options options);
-
-/*! \brief Get the sample rate associated with known RTP payload types
- *
- * \param isAstFormat True if the value in the 'code' parameter is an AST_FORMAT value
- * \param code Format code, either from AST_FORMAT list or from AST_RTP list
- *
- * \return the sample rate if the format was found, zero if it was not found
- */
-unsigned int ast_rtp_lookup_sample_rate(int isAstFormat, int code);
-
-/*! \brief Build a string of MIME subtype names from a capability list */
-char *ast_rtp_lookup_mime_multiple(char *buf, size_t size, const int capability,
- const int isAstFormat, enum ast_rtp_options options);
-
-void ast_rtp_setnat(struct ast_rtp *rtp, int nat);
-
-int ast_rtp_getnat(struct ast_rtp *rtp);
-
-/*! \brief Indicate whether this RTP session is carrying DTMF or not */
-void ast_rtp_setdtmf(struct ast_rtp *rtp, int dtmf);
-
-/*! \brief Compensate for devices that send RFC2833 packets all at once */
-void ast_rtp_setdtmfcompensate(struct ast_rtp *rtp, int compensate);
-
-/*! \brief Enable STUN capability */
-void ast_rtp_setstun(struct ast_rtp *rtp, int stun_enable);
-
-/*! \brief Generic STUN request
- * send a generic stun request to the server specified.
- * \param s the socket used to send the request
- * \param dst the address of the STUN server
- * \param username if non null, add the username in the request
- * \param answer if non null, the function waits for a response and
- * puts here the externally visible address.
- * \return 0 on success, other values on error.
- * The interface it may change in the future.
- */
-int ast_stun_request(int s, struct sockaddr_in *dst,
- const char *username, struct sockaddr_in *answer);
-
-/*! \brief Send STUN request for an RTP socket
- * Deprecated, this is just a wrapper for ast_rtp_stun_request()
- */
-void ast_rtp_stun_request(struct ast_rtp *rtp, struct sockaddr_in *suggestion, const char *username);
-
-/*! \brief The RTP bridge.
- \arg \ref AstRTPbridge
-*/
-int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
-
-/*! \brief Register an RTP channel client */
-int ast_rtp_proto_register(struct ast_rtp_protocol *proto);
-
-/*! \brief Unregister an RTP channel client */
-void ast_rtp_proto_unregister(struct ast_rtp_protocol *proto);
-
-int ast_rtp_make_compatible(struct ast_channel *dest, struct ast_channel *src, int media);
-
-/*! \brief If possible, create an early bridge directly between the devices without
- having to send a re-invite later */
-int ast_rtp_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
-
-/*! \brief Get QOS stats on a RTP channel
- * \since 1.6.1
- */
-int ast_rtp_get_qos(struct ast_rtp *rtp, const char *qos, char *buf, unsigned int buflen);
-
-/*! \brief Return RTP and RTCP QoS values
- * \since 1.6.1
- */
-unsigned int ast_rtp_get_qosvalue(struct ast_rtp *rtp, enum ast_rtp_qos_vars value);
-
-/*! \brief Set RTPAUDIOQOS(...) variables on a channel when it is being hung up
- * \since 1.6.1
- */
-void ast_rtp_set_vars(struct ast_channel *chan, struct ast_rtp *rtp);
-
-/*! \brief Return RTCP quality string
- *
- * \param rtp An rtp structure to get qos information about.
- *
- * \param qual An (optional) rtp quality structure that will be
- * filled with the quality information described in
- * the ast_rtp_quality structure. This structure is
- * not dependent on any qtype, so a call for any
- * type of information would yield the same results
- * because ast_rtp_quality is not a data type
- * specific to any qos type.
- *
- * \param qtype The quality type you'd like, default should be
- * RTPQOS_SUMMARY which returns basic information
- * about the call. The return from RTPQOS_SUMMARY
- * is basically ast_rtp_quality in a string. The
- * other types are RTPQOS_JITTER, RTPQOS_LOSS and
- * RTPQOS_RTT which will return more specific
- * statistics.
- * \version 1.6.1 added qtype parameter
- */
-char *ast_rtp_get_quality(struct ast_rtp *rtp, struct ast_rtp_quality *qual, enum ast_rtp_quality_type qtype);
-/*! \brief Send an H.261 fast update request. Some devices need this rather than the XML message in SIP */
-int ast_rtcp_send_h261fur(void *data);
-
-void ast_rtp_init(void); /*! Initialize RTP subsystem */
-int ast_rtp_reload(void); /*! reload rtp configuration */
-void ast_rtp_new_init(struct ast_rtp *rtp);
-
-/*! \brief Set codec preference */
-void ast_rtp_codec_setpref(struct ast_rtp *rtp, struct ast_codec_pref *prefs);
-
-/*! \brief Get codec preference */
-struct ast_codec_pref *ast_rtp_codec_getpref(struct ast_rtp *rtp);
-
-/*! \brief get format from predefined dynamic payload format */
-int ast_rtp_codec_getformat(int pt);
-
-/*! \brief Set rtp timeout */
-void ast_rtp_set_rtptimeout(struct ast_rtp *rtp, int timeout);
-/*! \brief Set rtp hold timeout */
-void ast_rtp_set_rtpholdtimeout(struct ast_rtp *rtp, int timeout);
-/*! \brief set RTP keepalive interval */
-void ast_rtp_set_rtpkeepalive(struct ast_rtp *rtp, int period);
-/*! \brief Get RTP keepalive interval */
-int ast_rtp_get_rtpkeepalive(struct ast_rtp *rtp);
-/*! \brief Get rtp hold timeout */
-int ast_rtp_get_rtpholdtimeout(struct ast_rtp *rtp);
-/*! \brief Get rtp timeout */
-int ast_rtp_get_rtptimeout(struct ast_rtp *rtp);
-/* \brief Put RTP timeout timers on hold during another transaction, like T.38 */
-void ast_rtp_set_rtptimers_onhold(struct ast_rtp *rtp);
-
-/*! \brief Initalize t.140 redudancy
- * \param ti time between each t140red frame is sent
- * \param red_pt payloadtype for RTP packet
- * \param pt payloadtype numbers for each generation including primary data
- * \param num_gen number of redundant generations, primary data excluded
- * \since 1.6.1
- */
-int ast_rtp_red_init(struct ast_rtp *rtp, int ti, int *pt, int num_gen);
-
-/*! \brief Buffer t.140 data */
-void ast_red_buffer_t140(struct ast_rtp *rtp, struct ast_frame *f);
-
-
-
-#if defined(__cplusplus) || defined(c_plusplus)
-}
-#endif
-
-#endif /* _ASTERISK_RTP_H */
--- /dev/null
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2009, Digium, Inc.
+ *
+ * Mark Spencer <markster@digium.com>
+ * Joshua Colp <jcolp@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 Pluggable RTP Architecture
+ * \author Joshua Colp <jcolp@digium.com>
+ * \ref AstRTPEngine
+ */
+
+/*!
+ * \page AstRTPEngine Asterisk RTP Engine API
+ *
+ * The purpose of this API is to provide a way for multiple RTP stacks to be used inside
+ * of Asterisk without any module that uses RTP knowing any different. To the module each RTP
+ * stack behaves the same.
+ *
+ * An RTP session is called an instance and is made up of a combination of codec information,
+ * RTP engine, RTP properties, and address information. An engine name may be passed in to explicitly
+ * choose an RTP stack to be used but a default one will be used if none is provided. An address to use
+ * for RTP may also be provided but the underlying RTP engine may choose a different address depending on
+ * it's configuration.
+ *
+ * An RTP engine is the layer between the RTP engine core and the RTP stack itself. The RTP engine core provides
+ * a set of callbacks to do various things (such as write audio out) that the RTP engine has to have implemented.
+ *
+ * Glue is what binds an RTP instance to a channel. It is used to retrieve RTP instance information when
+ * performing remote or local bridging and is used to have the channel driver tell the remote side to change
+ * destination of the RTP stream.
+ *
+ * Statistics from an RTP instance can be retrieved using the ast_rtp_instance_get_stats API call. This essentially
+ * asks the RTP engine in use to fill in a structure with the requested values. It is not required for an RTP engine
+ * to support all statistic values.
+ *
+ * Properties allow behavior of the RTP engine and RTP engine core to be changed. For example, there is a property named
+ * AST_RTP_PROPERTY_NAT which is used to tell the RTP engine to enable symmetric RTP if it supports it. It is not required
+ * for an RTP engine to support all properties.
+ *
+ * Codec information is stored using a separate data structure which has it's own set of API calls to add/remove/retrieve
+ * information. They are used by the module after an RTP instance is created so that payload information is available for
+ * the RTP engine.
+ */
+
+#ifndef _ASTERISK_RTP_ENGINE_H
+#define _ASTERISK_RTP_ENGINE_H
+
+#if defined(__cplusplus) || defined(c_plusplus)
+extern "C" {
+#endif
+
+#include "asterisk/astobj2.h"
+
+/* Maximum number of payloads supported */
+#define AST_RTP_MAX_PT 256
+
+/* Maximum number of generations */
+#define AST_RED_MAX_GENERATION 5
+
+struct ast_rtp_instance;
+struct ast_rtp_glue;
+
+/*! RTP Properties that can be set on an RTP instance */
+enum ast_rtp_property {
+ /*! Enable symmetric RTP support */
+ AST_RTP_PROPERTY_NAT = 0,
+ /*! RTP instance will be carrying DTMF (using RFC2833) */
+ AST_RTP_PROPERTY_DTMF,
+ /*! Expect unreliable DTMF from remote party */
+ AST_RTP_PROPERTY_DTMF_COMPENSATE,
+ /*! Enable STUN support */
+ AST_RTP_PROPERTY_STUN,
+ /*! Enable RTCP support */
+ AST_RTP_PROPERTY_RTCP,
+ /*! Maximum number of RTP properties supported */
+ AST_RTP_PROPERTY_MAX,
+};
+
+/*! Additional RTP options */
+enum ast_rtp_options {
+ /*! Remote side is using non-standard G.726 */
+ AST_RTP_OPT_G726_NONSTANDARD = (1 << 0),
+};
+
+/*! RTP DTMF Modes */
+enum ast_rtp_dtmf_mode {
+ /*! No DTMF is being carried over the RTP stream */
+ AST_RTP_DTMF_MODE_NONE = 0,
+ /*! DTMF is being carried out of band using RFC2833 */
+ AST_RTP_DTMF_MODE_RFC2833,
+ /*! DTMF is being carried inband over the RTP stream */
+ AST_RTP_DTMF_MODE_INBAND,
+};
+
+/*! Result codes when RTP glue is queried for information */
+enum ast_rtp_glue_result {
+ /*! No remote or local bridging is permitted */
+ AST_RTP_GLUE_RESULT_FORBID = 0,
+ /*! Move RTP stream to be remote between devices directly */
+ AST_RTP_GLUE_RESULT_REMOTE,
+ /*! Perform RTP engine level bridging if possible */
+ AST_RTP_GLUE_RESULT_LOCAL,
+};
+
+/*! Field statistics that can be retrieved from an RTP instance */
+enum ast_rtp_instance_stat_field {
+ /*! Retrieve quality information */
+ AST_RTP_INSTANCE_STAT_FIELD_QUALITY = 0,
+ /*! Retrieve quality information about jitter */
+ AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER,
+ /*! Retrieve quality information about packet loss */
+ AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS,
+ /*! Retrieve quality information about round trip time */
+ AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT,
+};
+
+/*! Statistics that can be retrieved from an RTP instance */
+enum ast_rtp_instance_stat {
+ /*! Retrieve all statistics */
+ AST_RTP_INSTANCE_STAT_ALL = 0,
+ /*! Retrieve number of packets transmitted */
+ AST_RTP_INSTANCE_STAT_TXCOUNT,
+ /*! Retrieve number of packets received */
+ AST_RTP_INSTANCE_STAT_RXCOUNT,
+ /*! Retrieve ALL statistics relating to packet loss */
+ AST_RTP_INSTANCE_STAT_COMBINED_LOSS,
+ /*! Retrieve number of packets lost for transmitting */
+ AST_RTP_INSTANCE_STAT_TXPLOSS,
+ /*! Retrieve number of packets lost for receiving */
+ AST_RTP_INSTANCE_STAT_RXPLOSS,
+ /*! Retrieve maximum number of packets lost on remote side */
+ AST_RTP_INSTANCE_STAT_REMOTE_MAXRXPLOSS,
+ /*! Retrieve minimum number of packets lost on remote side */
+ AST_RTP_INSTANCE_STAT_REMOTE_MINRXPLOSS,
+ /*! Retrieve average number of packets lost on remote side */
+ AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVRXPLOSS,
+ /*! Retrieve standard deviation of packets lost on remote side */
+ AST_RTP_INSTANCE_STAT_REMOTE_STDEVRXPLOSS,
+ /*! Retrieve maximum number of packets lost on local side */
+ AST_RTP_INSTANCE_STAT_LOCAL_MAXRXPLOSS,
+ /*! Retrieve minimum number of packets lost on local side */
+ AST_RTP_INSTANCE_STAT_LOCAL_MINRXPLOSS,
+ /*! Retrieve average number of packets lost on local side */
+ AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVRXPLOSS,
+ /*! Retrieve standard deviation of packets lost on local side */
+ AST_RTP_INSTANCE_STAT_LOCAL_STDEVRXPLOSS,
+ /*! Retrieve ALL statistics relating to jitter */
+ AST_RTP_INSTANCE_STAT_COMBINED_JITTER,
+ /*! Retrieve jitter on transmitted packets */
+ AST_RTP_INSTANCE_STAT_TXJITTER,
+ /*! Retrieve jitter on received packets */
+ AST_RTP_INSTANCE_STAT_RXJITTER,
+ /*! Retrieve maximum jitter on remote side */
+ AST_RTP_INSTANCE_STAT_REMOTE_MAXJITTER,
+ /*! Retrieve minimum jitter on remote side */
+ AST_RTP_INSTANCE_STAT_REMOTE_MINJITTER,
+ /*! Retrieve average jitter on remote side */
+ AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVJITTER,
+ /*! Retrieve standard deviation jitter on remote side */
+ AST_RTP_INSTANCE_STAT_REMOTE_STDEVJITTER,
+ /*! Retrieve maximum jitter on local side */
+ AST_RTP_INSTANCE_STAT_LOCAL_MAXJITTER,
+ /*! Retrieve minimum jitter on local side */
+ AST_RTP_INSTANCE_STAT_LOCAL_MINJITTER,
+ /*! Retrieve average jitter on local side */
+ AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVJITTER,
+ /*! Retrieve standard deviation jitter on local side */
+ AST_RTP_INSTANCE_STAT_LOCAL_STDEVJITTER,
+ /*! Retrieve ALL statistics relating to round trip time */
+ AST_RTP_INSTANCE_STAT_COMBINED_RTT,
+ /*! Retrieve round trip time */
+ AST_RTP_INSTANCE_STAT_RTT,
+ /*! Retrieve maximum round trip time */
+ AST_RTP_INSTANCE_STAT_MAX_RTT,
+ /*! Retrieve minimum round trip time */
+ AST_RTP_INSTANCE_STAT_MIN_RTT,
+ /*! Retrieve average round trip time */
+ AST_RTP_INSTANCE_STAT_NORMDEVRTT,
+ /*! Retrieve standard deviation round trip time */
+ AST_RTP_INSTANCE_STAT_STDEVRTT,
+ /*! Retrieve local SSRC */
+ AST_RTP_INSTANCE_STAT_LOCAL_SSRC,
+ /*! Retrieve remote SSRC */
+ AST_RTP_INSTANCE_STAT_REMOTE_SSRC,
+};
+
+/* Codes for RTP-specific data - not defined by our AST_FORMAT codes */
+/*! DTMF (RFC2833) */
+#define AST_RTP_DTMF (1 << 0)
+/*! 'Comfort Noise' (RFC3389) */
+#define AST_RTP_CN (1 << 1)
+/*! DTMF (Cisco Proprietary) */
+#define AST_RTP_CISCO_DTMF (1 << 2)
+/*! Maximum RTP-specific code */
+#define AST_RTP_MAX AST_RTP_CISCO_DTMF
+
+/*! Structure that represents a payload */
+struct ast_rtp_payload_type {
+ /*! Is this an Asterisk value */
+ int asterisk_format;
+ /*! Actual internal value of the payload */
+ int code;
+};
+
+/*! Structure that represents statistics from an RTP instance */
+struct ast_rtp_instance_stats {
+ /*! Number of packets transmitted */
+ unsigned int txcount;
+ /*! Number of packets received */
+ unsigned int rxcount;
+ /*! Jitter on transmitted packets */
+ unsigned int txjitter;
+ /*! Jitter on received packets */
+ unsigned int rxjitter;
+ /*! Maximum jitter on remote side */
+ double remote_maxjitter;
+ /*! Minimum jitter on remote side */
+ double remote_minjitter;
+ /*! Average jitter on remote side */
+ double remote_normdevjitter;
+ /*! Standard deviation jitter on remote side */
+ double remote_stdevjitter;
+ /*! Maximum jitter on local side */
+ double local_maxjitter;
+ /*! Minimum jitter on local side */
+ double local_minjitter;
+ /*! Average jitter on local side */
+ double local_normdevjitter;
+ /*! Standard deviation jitter on local side */
+ double local_stdevjitter;
+ /*! Number of transmitted packets lost */
+ unsigned int txploss;
+ /*! Number of received packets lost */
+ unsigned int rxploss;
+ /*! Maximum number of packets lost on remote side */
+ double remote_maxrxploss;
+ /*! Minimum number of packets lost on remote side */
+ double remote_minrxploss;
+ /*! Average number of packets lost on remote side */
+ double remote_normdevrxploss;
+ /*! Standard deviation packets lost on remote side */
+ double remote_stdevrxploss;
+ /*! Maximum number of packets lost on local side */
+ double local_maxrxploss;
+ /*! Minimum number of packets lost on local side */
+ double local_minrxploss;
+ /*! Average number of packets lost on local side */
+ double local_normdevrxploss;
+ /*! Standard deviation packets lost on local side */
+ double local_stdevrxploss;
+ /*! Total round trip time */
+ unsigned int rtt;
+ /*! Maximum round trip time */
+ double maxrtt;
+ /*! Minimum round trip time */
+ double minrtt;
+ /*! Average round trip time */
+ double normdevrtt;
+ /*! Standard deviation round trip time */
+ double stdevrtt;
+ /*! Our SSRC */
+ unsigned int local_ssrc;
+ /*! Their SSRC */
+ unsigned int remote_ssrc;
+};
+
+#define AST_RTP_STAT_SET(current_stat, combined, placement, value) \
+if (stat == current_stat || stat == AST_RTP_INSTANCE_STAT_ALL || (combined >= 0 && combined == current_stat)) { \
+placement = value; \
+if (stat == current_stat) { \
+return 0; \
+} \
+}
+
+#define AST_RTP_STAT_TERMINATOR(combined) \
+if (stat == combined) { \
+return 0; \
+}
+
+/*! Structure that represents an RTP stack (engine) */
+struct ast_rtp_engine {
+ /*! Name of the RTP engine, used when explicitly requested */
+ const char *name;
+ /*! Module this RTP engine came from, used for reference counting */
+ struct ast_module *mod;
+ /*! Callback for setting up a new RTP instance */
+ int (*new)(struct ast_rtp_instance *instance, struct sched_context *sched, struct sockaddr_in *sin, void *data);
+ /*! Callback for destroying an RTP instance */
+ int (*destroy)(struct ast_rtp_instance *instance);
+ /*! Callback for writing out a frame */
+ int (*write)(struct ast_rtp_instance *instance, struct ast_frame *frame);
+ /*! Callback for stopping the RTP instance */
+ void (*stop)(struct ast_rtp_instance *instance);
+ /*! Callback for starting RFC2833 DTMF transmission */
+ int (*dtmf_begin)(struct ast_rtp_instance *instance, char digit);
+ /*! Callback for stopping RFC2833 DTMF transmission */
+ int (*dtmf_end)(struct ast_rtp_instance *instance, char digit);
+ /*! Callback to indicate that a new source of media has come in */
+ void (*new_source)(struct ast_rtp_instance *instance);
+ /*! Callback for setting an extended RTP property */
+ int (*extended_prop_set)(struct ast_rtp_instance *instance, int property, void *value);
+ /*! Callback for getting an extended RTP property */
+ void *(*extended_prop_get)(struct ast_rtp_instance *instance, int property);
+ /*! Callback for setting an RTP property */
+ void (*prop_set)(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value);
+ /*! Callback for setting a payload */
+ void (*payload_set)(struct ast_rtp_instance *instance, int payload, int astformat, int format);
+ /*! Callback for setting packetization preferences */
+ void (*packetization_set)(struct ast_rtp_instance *instance, struct ast_codec_pref *pref);
+ /*! Callback for setting the remote address that RTP is to be sent to */
+ void (*remote_address_set)(struct ast_rtp_instance *instance, struct sockaddr_in *sin);
+ /*! Callback for changing DTMF mode */
+ int (*dtmf_mode_set)(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode);
+ /*! Callback for retrieving statistics */
+ int (*get_stat)(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat);
+ /*! Callback for setting QoS values */
+ int (*qos)(struct ast_rtp_instance *instance, int tos, int cos, const char *desc);
+ /*! Callback for retrieving a file descriptor to poll on, not always required */
+ int (*fd)(struct ast_rtp_instance *instance, int rtcp);
+ /*! Callback for initializing RED support */
+ int (*red_init)(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations);
+ /*! Callback for buffering a frame using RED */
+ int (*red_buffer)(struct ast_rtp_instance *instance, struct ast_frame *frame);
+ /*! Callback for reading a frame from the RTP engine */
+ struct ast_frame *(*read)(struct ast_rtp_instance *instance, int rtcp);
+ /*! Callback to locally bridge two RTP instances */
+ int (*local_bridge)(struct ast_rtp_instance *instance0, struct ast_rtp_instance *instance1);
+ /*! Callback to set the read format */
+ int (*set_read_format)(struct ast_rtp_instance *instance, int format);
+ /*! Callback to set the write format */
+ int (*set_write_format)(struct ast_rtp_instance *instance, int format);
+ /*! Callback to make two instances compatible */
+ int (*make_compatible)(struct ast_channel *chan0, struct ast_rtp_instance *instance0, struct ast_channel *chan1, struct ast_rtp_instance *instance1);
+ /*! Callback to see if two instances are compatible with DTMF */
+ int (*dtmf_compatible)(struct ast_channel *chan0, struct ast_rtp_instance *instance0, struct ast_channel *chan1, struct ast_rtp_instance *instance1);
+ /*! Callback to indicate that packets will now flow */
+ int (*activate)(struct ast_rtp_instance *instance);
+ /*! Callback to request that the RTP engine send a STUN BIND request */
+ void (*stun_request)(struct ast_rtp_instance *instance, struct sockaddr_in *suggestion, const char *username);
+ /*! Linked list information */
+ AST_RWLIST_ENTRY(ast_rtp_engine) entry;
+};
+
+/*! Structure that represents codec and packetization information */
+struct ast_rtp_codecs {
+ /*! Codec packetization preferences */
+ struct ast_codec_pref pref;
+ /*! Payloads present */
+ struct ast_rtp_payload_type payloads[AST_RTP_MAX_PT];
+};
+
+/*! Structure that represents the glue that binds an RTP instance to a channel */
+struct ast_rtp_glue {
+ /*! Name of the channel driver that this glue is responsible for */
+ const char *type;
+ /*! Module that the RTP glue came from */
+ struct ast_module *mod;
+ /*!
+ * \brief Callback for retrieving the RTP instance carrying audio
+ * \note This function increases the reference count on the returned RTP instance.
+ */
+ enum ast_rtp_glue_result (*get_rtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance);
+ /*!
+ * \brief Callback for retrieving the RTP instance carrying video
+ * \note This function increases the reference count on the returned RTP instance.
+ */
+ enum ast_rtp_glue_result (*get_vrtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance);
+ /*!
+ * \brief Callback for retrieving the RTP instance carrying text
+ * \note This function increases the reference count on the returned RTP instance.
+ */
+ enum ast_rtp_glue_result (*get_trtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance);
+ /*! Callback for updating the destination that the remote side should send RTP to */
+ int (*update_peer)(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, int codecs, int nat_active);
+ /*! Callback for retrieving codecs that the channel can do */
+ int (*get_codec)(struct ast_channel *chan);
+ /*! Linked list information */
+ AST_RWLIST_ENTRY(ast_rtp_glue) entry;
+};
+
+#define ast_rtp_engine_register(engine) ast_rtp_engine_register2(engine, ast_module_info->self)
+
+/*!
+ * \brief Register an RTP engine
+ *
+ * \param engine Structure of the RTP engine to register
+ * \param module Module that the RTP engine is part of
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_engine_register2(&example_rtp_engine, NULL);
+ * \endcode
+ *
+ * This registers the RTP engine declared as example_rtp_engine with the RTP engine core, but does not
+ * associate a module with it.
+ *
+ * \note It is recommended that you use the ast_rtp_engine_register macro so that the module is
+ * associated with the RTP engine and use counting is performed.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_engine_register2(struct ast_rtp_engine *engine, struct ast_module *module);
+
+/*!
+ * \brief Unregister an RTP engine
+ *
+ * \param engine Structure of the RTP engine to unregister
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_engine_unregister(&example_rtp_engine);
+ * \endcode
+ *
+ * This unregisters the RTP engine declared as example_rtp_engine from the RTP engine core. If a module
+ * reference was provided when it was registered then this will only be called once the RTP engine is no longer in use.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_engine_unregister(struct ast_rtp_engine *engine);
+
+#define ast_rtp_glue_register(glue) ast_rtp_glue_register2(glue, ast_module_info->self)
+
+/*!
+ * \brief Register RTP glue
+ *
+ * \param glue The glue to register
+ * \param module Module that the RTP glue is part of
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_glue_register2(&example_rtp_glue, NULL);
+ * \endcode
+ *
+ * This registers the RTP glue declared as example_rtp_glue with the RTP engine core, but does not
+ * associate a module with it.
+ *
+ * \note It is recommended that you use the ast_rtp_glue_register macro so that the module is
+ * associated with the RTP glue and use counting is performed.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_glue_register2(struct ast_rtp_glue *glue, struct ast_module *module);
+
+/*!
+ * \brief Unregister RTP glue
+ *
+ * \param glue The glue to unregister
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_glue_unregister(&example_rtp_glue);
+ * \endcode
+ *
+ * This unregisters the RTP glue declared as example_rtp_gkue from the RTP engine core. If a module
+ * reference was provided when it was registered then this will only be called once the RTP engine is no longer in use.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_glue_unregister(struct ast_rtp_glue *glue);
+
+/*!
+ * \brief Create a new RTP instance
+ *
+ * \param engine_name Name of the engine to use for the RTP instance
+ * \param sched Scheduler context that the RTP engine may want to use
+ * \param sin Address we want to bind to
+ * \param data Unique data for the engine
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ *
+ * Example usage:
+ *
+ * \code
+ * struct ast_rtp_instance *instance = NULL;
+ * instance = ast_rtp_instance_new(NULL, sched, &sin, NULL);
+ * \endcode
+ *
+ * This creates a new RTP instance using the default engine and asks the RTP engine to bind to the address given
+ * in the sin structure.
+ *
+ * \note The RTP engine does not have to use the address provided when creating an RTP instance. It may choose to use
+ * another depending on it's own configuration.
+ *
+ * \since 1.6.3
+ */
+struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name, struct sched_context *sched, struct sockaddr_in *sin, void *data);
+
+/*!
+ * \brief Destroy an RTP instance
+ *
+ * \param instance The RTP instance to destroy
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_destroy(instance);
+ * \endcode
+ *
+ * This destroys the RTP instance pointed to by instance. Once this function returns instance no longer points to valid
+ * memory and may not be used again.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_destroy(struct ast_rtp_instance *instance);
+
+/*!
+ * \brief Set the data portion of an RTP instance
+ *
+ * \param instance The RTP instance to manipulate
+ * \param data Pointer to data
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_set_data(instance, blob);
+ * \endcode
+ *
+ * This sets the data pointer on the RTP instance pointed to by 'instance' to
+ * blob.
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_instance_set_data(struct ast_rtp_instance *instance, void *data);
+
+/*!
+ * \brief Get the data portion of an RTP instance
+ *
+ * \param instance The RTP instance we want the data portion from
+ *
+ * Example usage:
+ *
+ * \code
+ * struct *blob = ast_rtp_instance_get_data(instance);
+ ( \endcode
+ *
+ * This gets the data pointer on the RTP instance pointed to by 'instance'.
+ *
+ * \since 1.6.3
+ */
+void *ast_rtp_instance_get_data(struct ast_rtp_instance *instance);
+
+/*!
+ * \brief Send a frame out over RTP
+ *
+ * \param instance The RTP instance to send frame out on
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_write(instance, frame);
+ * \endcode
+ *
+ * This gives the frame pointed to by frame to the RTP engine being used for the instance
+ * and asks that it be transmitted to the current remote address set on the RTP instance.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_write(struct ast_rtp_instance *instance, struct ast_frame *frame);
+
+/*!
+ * \brief Receive a frame over RTP
+ *
+ * \param instance The RTP instance to receive frame on
+ * \param rtcp Whether to read in RTCP or not
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ *
+ * Example usage:
+ *
+ * \code
+ * struct ast_frame *frame;
+ * frame = ast_rtp_instance_read(instance, 0);
+ * \endcode
+ *
+ * This asks the RTP engine to read in RTP from the instance and return it as an Asterisk frame.
+ *
+ * \since 1.6.3
+ */
+struct ast_frame *ast_rtp_instance_read(struct ast_rtp_instance *instance, int rtcp);
+
+/*!
+ * \brief Set the address of the remote endpoint that we are sending RTP to
+ *
+ * \param instance The RTP instance to change the address on
+ * \param address Address to set it to
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_set_remote_address(instance, &sin);
+ * \endcode
+ *
+ * This changes the remote address that RTP will be sent to on instance to the address given in the sin
+ * structure.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_set_remote_address(struct ast_rtp_instance *instance, struct sockaddr_in *address);
+
+/*!
+ * \brief Set the address that we are expecting to receive RTP on
+ *
+ * \param instance The RTP instance to change the address on
+ * \param address Address to set it to
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_set_local_address(instance, &sin);
+ * \endcode
+ *
+ * This changes the local address that RTP is expected on to the address given in the sin
+ * structure.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_set_local_address(struct ast_rtp_instance *instance, struct sockaddr_in *address);
+
+/*!
+ * \brief Get the local address that we are expecting RTP on
+ *
+ * \param instance The RTP instance to get the address from
+ * \param address The variable to store the address in
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * struct sockaddr_in sin;
+ * ast_rtp_instance_get_local_address(instance, &sin);
+ * \endcode
+ *
+ * This gets the local address that we are expecting RTP on and stores it in the 'sin' structure.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_get_local_address(struct ast_rtp_instance *instance, struct sockaddr_in *address);
+
+/*!
+ * \brief Get the address of the remote endpoint that we are sending RTP to
+ *
+ * \param instance The instance that we want to get the remote address for
+ * \param address A structure to put the address into
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * struct sockaddr_in sin;
+ * ast_rtp_instance_get_remote_address(instance, &sin);
+ * \endcode
+ *
+ * This retrieves the current remote address set on the instance pointed to by instance and puts the value
+ * into the sin structure.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_get_remote_address(struct ast_rtp_instance *instance, struct sockaddr_in *address);
+
+/*!
+ * \brief Set the value of an RTP instance extended property
+ *
+ * \param instance The RTP instance to set the extended property on
+ * \param property The extended property to set
+ * \param value The value to set the extended property to
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_instance_set_extended_prop(struct ast_rtp_instance *instance, int property, void *value);
+
+/*!
+ * \brief Get the value of an RTP instance extended property
+ *
+ * \param instance The RTP instance to get the extended property on
+ * \param property The extended property to get
+ *
+ * \since 1.6.3
+ */
+void *ast_rtp_instance_get_extended_prop(struct ast_rtp_instance *instance, int property);
+
+/*!
+ * \brief Set the value of an RTP instance property
+ *
+ * \param instance The RTP instance to set the property on
+ * \param property The property to modify
+ * \param value The value to set the property to
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_set_prop(instance, AST_RTP_PROPERTY_NAT, 1);
+ * \endcode
+ *
+ * This enables the AST_RTP_PROPERTY_NAT property on the instance pointed to by instance.
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_instance_set_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value);
+
+/*!
+ * \brief Get the value of an RTP instance property
+ *
+ * \param instance The RTP instance to get the property from
+ * \param property The property to get
+ *
+ * \retval Current value of the property
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_get_prop(instance, AST_RTP_PROPERTY_NAT);
+ * \endcode
+ *
+ * This returns the current value of the NAT property on the instance pointed to by instance.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_get_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property);
+
+/*!
+ * \brief Get the codecs structure of an RTP instance
+ *
+ * \param instance The RTP instance to get the codecs structure from
+ *
+ * Example usage:
+ *
+ * \code
+ * struct ast_rtp_codecs *codecs = ast_rtp_instance_get_codecs(instance);
+ * \endcode
+ *
+ * This gets the codecs structure on the RTP instance pointed to by 'instance'.
+ *
+ * \since 1.6.3
+ */
+struct ast_rtp_codecs *ast_rtp_instance_get_codecs(struct ast_rtp_instance *instance);
+
+/*!
+ * \brief Clear payload information from an RTP instance
+ *
+ * \param codecs The codecs structure that payloads will be cleared from
+ * \param instance Optionally the instance that the codecs structure belongs to
+ *
+ * Example usage:
+ *
+ * \code
+ * struct ast_rtp_codecs codecs;
+ * ast_rtp_codecs_payloads_clear(&codecs, NULL);
+ * \endcode
+ *
+ * This clears the codecs structure and puts it into a pristine state.
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_codecs_payloads_clear(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance);
+
+/*!
+ * \brief Set payload information on an RTP instance to the default
+ *
+ * \param codecs The codecs structure to set defaults on
+ * \param instance Optionally the instance that the codecs structure belongs to
+ *
+ * Example usage:
+ *
+ * \code
+ * struct ast_rtp_codecs codecs;
+ * ast_rtp_codecs_payloads_default(&codecs, NULL);
+ * \endcode
+ *
+ * This sets the default payloads on the codecs structure.
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_codecs_payloads_default(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance);
+
+/*!
+ * \brief Copy payload information from one RTP instance to another
+ *
+ * \param src The source codecs structure
+ * \param dst The destination codecs structure that the values from src will be copied to
+ * \param instance Optionally the instance that the dst codecs structure belongs to
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_codecs_payloads_copy(&codecs0, &codecs1, NULL);
+ * \endcode
+ *
+ * This copies the payloads from the codecs0 structure to the codecs1 structure, overwriting any current values.
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance);
+
+/*!
+ * \brief Record payload information that was seen in an m= SDP line
+ *
+ * \param codecs The codecs structure to muck with
+ * \param instance Optionally the instance that the codecs structure belongs to
+ * \param payload Numerical payload that was seen in the m= SDP line
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_codecs_payloads_set_m_type(&codecs, NULL, 0);
+ * \endcode
+ *
+ * This records that the numerical payload '0' was seen in the codecs structure.
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload);
+
+/*!
+ * \brief Record payload information that was seen in an a=rtpmap: SDP line
+ *
+ * \param codecs The codecs structure to muck with
+ * \param instance Optionally the instance that the codecs structure belongs to
+ * \param payload Numerical payload that was seen in the a=rtpmap: SDP line
+ * \param mimetype The string mime type that was seen
+ * \param mimesubtype The strin mime sub type that was seen
+ * \param options Optional options that may change the behavior of this specific payload
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_codecs_payloads_set_rtpmap_type(&codecs, NULL, 0, "audio", "PCMU", 0);
+ * \endcode
+ *
+ * This records that the numerical payload '0' was seen with mime type 'audio' and sub mime type 'PCMU' in the codecs structure.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_codecs_payloads_set_rtpmap_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload, char *mimetype, char *mimesubtype, enum ast_rtp_options options);
+
+/*!
+ * \brief Set payload type to a known MIME media type for a codec with a specific sample rate
+ *
+ * \param rtp RTP structure to modify
+ * \param instance Optionally the instance that the codecs structure belongs to
+ * \param pt Payload type entry to modify
+ * \param mimetype top-level MIME type of media stream (typically "audio", "video", "text", etc.)
+ * \param mimesubtype MIME subtype of media stream (typically a codec name)
+ * \param options Zero or more flags from the ast_rtp_options enum
+ * \param sample_rate The sample rate of the media stream
+ *
+ * This function 'fills in' an entry in the list of possible formats for
+ * a media stream associated with an RTP structure.
+ *
+ * \retval 0 on success
+ * \retval -1 if the payload type is out of range
+ * \retval -2 if the mimeType/mimeSubtype combination was not found
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int pt,
+ char *mimetype, char *mimesubtype,
+ enum ast_rtp_options options,
+ unsigned int sample_rate);
+
+/*!
+ * \brief Remove payload information
+ *
+ * \param codecs The codecs structure to muck with
+ * \param instance Optionally the instance that the codecs structure belongs to
+ * \param payload Numerical payload to unset
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_codecs_payloads_unset(&codecs, NULL, 0);
+ * \endcode
+ *
+ * This clears the payload '0' from the codecs structure. It will be as if it was never set.
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload);
+
+/*!
+ * \brief Retrieve payload information by payload
+ *
+ * \param codecs Codecs structure to look in
+ * \param payload Numerical payload to look up
+ *
+ * \retval Payload information
+ *
+ * Example usage:
+ *
+ * \code
+ * struct ast_rtp_payload_type payload_type;
+ * payload_type = ast_rtp_codecs_payload_lookup(&codecs, 0);
+ * \endcode
+ *
+ * This looks up the information for payload '0' from the codecs structure.
+ *
+ * \since 1.6.3
+ */
+struct ast_rtp_payload_type ast_rtp_codecs_payload_lookup(struct ast_rtp_codecs *codecs, int payload);
+
+/*!
+ * \brief Get the sample rate associated with known RTP payload types
+ *
+ * \param asterisk_format True if the value in the 'code' parameter is an AST_FORMAT value
+ * \param code Format code, either from AST_FORMAT list or from AST_RTP list
+ *
+ * \return the sample rate if the format was found, zero if it was not found
+ *
+ * \since 1.6.3
+ */
+unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format, int code);
+
+/*!
+ * \brief Retrieve all formats that were found
+ *
+ * \param codecs Codecs structure to look in
+ * \param astFormats An integer to put the Asterisk formats in
+ * \param nonastformats An integer to put the non-Asterisk formats in
+ *
+ * Example usage:
+ *
+ * \code
+ * int astformats, nonastformats;
+ * ast_rtp_codecs_payload_Formats(&codecs, &astformats, &nonastformats);
+ * \endcode
+ *
+ * This retrieves all the formats known about in the codecs structure and puts the Asterisk ones in the integer
+ * pointed to by astformats and the non-Asterisk ones in the integer pointed to by nonastformats.
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_codecs_payload_formats(struct ast_rtp_codecs *codecs, int *astformats, int *nonastformats);
+
+/*!
+ * \brief Retrieve a payload based on whether it is an Asterisk format and the code
+ *
+ * \param codecs Codecs structure to look in
+ * \param asterisk_format Non-zero if the given code is an Asterisk format value
+ * \param code The format to look for
+ *
+ * \retval Numerical payload
+ *
+ * Example usage:
+ *
+ * \code
+ * int payload = ast_rtp_codecs_payload_code(&codecs, 1, AST_FORMAT_ULAW);
+ * \endcode
+ *
+ * This looks for the numerical payload for ULAW in the codecs structure.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_codecs_payload_code(struct ast_rtp_codecs *codecs, const int asterisk_format, const int code);
+
+/*!
+ * \brief Retrieve mime subtype information on a payload
+ *
+ * \param asterisk_format Non-zero if the given code is an Asterisk format value
+ * \param code Format to look up
+ * \param options Additional options that may change the result
+ *
+ * \retval Mime subtype success
+ * \retval NULL failure
+ *
+ * Example usage:
+ *
+ * \code
+ * const char *subtype = ast_rtp_lookup_mime_subtype2(1, AST_FORMAT_ULAW, 0);
+ * \endcode
+ *
+ * This looks up the mime subtype for the ULAW format.
+ *
+ * \since 1.6.3
+ */
+const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format, const int code, enum ast_rtp_options options);
+
+/*!
+ * \brief Convert formats into a string and put them into a buffer
+ *
+ * \param buf Buffer to put the mime output into
+ * \param capability Formats that we are looking up
+ * \param asterisk_format Non-zero if the given capability are Asterisk format capabilities
+ * \param options Additional options that may change the result
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ *
+ * Example usage:
+ *
+ * \code
+ * char buf[256] = "";
+ * char *mime = ast_rtp_lookup_mime_multiple2(&buf, sizeof(buf), AST_FORMAT_ULAW | AST_FORMAT_ALAW, 1, 0);
+ * \endcode
+ *
+ * This returns the mime values for ULAW and ALAW in the buffer pointed to by buf.
+ *
+ * \since 1.6.3
+ */
+char *ast_rtp_lookup_mime_multiple2(struct ast_str *buf, const int capability, const int asterisk_format, enum ast_rtp_options options);
+
+/*!
+ * \brief Set codec packetization preferences
+ *
+ * \param codecs Codecs structure to muck with
+ * \param instance Optionally the instance that the codecs structure belongs to
+ * \param prefs Codec packetization preferences
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_codecs_packetization_set(&codecs, NULL, &prefs);
+ * \endcode
+ *
+ * This sets the packetization preferences pointed to by prefs on the codecs structure pointed to by codecs.
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_codecs_packetization_set(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, struct ast_codec_pref *prefs);
+
+/*!
+ * \brief Begin sending a DTMF digit
+ *
+ * \param instance The RTP instance to send the DTMF on
+ * \param digit What DTMF digit to send
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_dtmf_begin(instance, '1');
+ * \endcode
+ *
+ * This starts sending the DTMF '1' on the RTP instance pointed to by instance. It will
+ * continue being sent until it is ended.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_dtmf_begin(struct ast_rtp_instance *instance, char digit);
+
+/*!
+ * \brief Stop sending a DTMF digit
+ *
+ * \param instance The RTP instance to stop the DTMF on
+ * \param digit What DTMF digit to stop
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_dtmf_end(instance, '1');
+ * \endcode
+ *
+ * This stops sending the DTMF '1' on the RTP instance pointed to by instance.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_dtmf_end(struct ast_rtp_instance *instance, char digit);
+
+/*!
+ * \brief Set the DTMF mode that should be used
+ *
+ * \param instance the RTP instance to set DTMF mode on
+ * \param dtmf_mode The DTMF mode that is in use
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_dtmf_mode_set(instance, AST_RTP_DTMF_MODE_RFC2833);
+ * \endcode
+ *
+ * This sets the RTP instance to use RFC2833 for DTMF transmission and receiving.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_dtmf_mode_set(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode);
+
+/*!
+ * \brief Get the DTMF mode of an RTP instance
+ *
+ * \param instance The RTP instance to get the DTMF mode of
+ *
+ * \retval DTMF mode
+ *
+ * Example usage:
+ *
+ * \code
+ * enum ast_rtp_dtmf_mode dtmf_mode = ast_rtp_instance_dtmf_mode_get(instance);
+ * \endcode
+ *
+ * This gets the DTMF mode set on the RTP instance pointed to by 'instance'.
+ *
+ * \since 1.6.3
+ */
+enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get(struct ast_rtp_instance *instance);
+
+/*!
+ * \brief Indicate a new source of audio has dropped in
+ *
+ * \param instance Instance that the new media source is feeding into
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_new_source(instance);
+ * \endcode
+ *
+ * This indicates that a new source of media is feeding the instance pointed to by
+ * instance.
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_instance_new_source(struct ast_rtp_instance *instance);
+
+/*!
+ * \brief Set QoS parameters on an RTP session
+ *
+ * \param instance Instance to set the QoS parameters on
+ * \param tos Terms of service value
+ * \param cos Class of service value
+ * \param desc What is setting the QoS values
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_set_qos(instance, 0, 0, "Example");
+ * \endcode
+ *
+ * This sets the TOS and COS values to 0 on the instance pointed to by instance.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_set_qos(struct ast_rtp_instance *instance, int tos, int cos, const char *desc);
+
+/*!
+ * \brief Stop an RTP instance
+ *
+ * \param instance Instance that media is no longer going to at this time
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_stop(instance);
+ * \endcode
+ *
+ * This tells the RTP engine being used for the instance pointed to by instance
+ * that media is no longer going to it at this time, but may in the future.
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_instance_stop(struct ast_rtp_instance *instance);
+
+/*!
+ * \brief Get the file descriptor for an RTP session (or RTCP)
+ *
+ * \param instance Instance to get the file descriptor for
+ * \param rtcp Whether to retrieve the file descriptor for RTCP or not
+ *
+ * \retval fd success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * int rtp_fd = ast_rtp_instance_fd(instance, 0);
+ * \endcode
+ *
+ * This retrieves the file descriptor for the socket carrying media on the instance
+ * pointed to by instance.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_fd(struct ast_rtp_instance *instance, int rtcp);
+
+/*!
+ * \brief Get the RTP glue that binds a channel to the RTP engine
+ *
+ * \param type Name of the glue we want
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ *
+ * Example usage:
+ *
+ * \code
+ * struct ast_rtp_glue *glue = ast_rtp_instance_get_glue("Example");
+ * \endcode
+ *
+ * This retrieves the RTP glue that has the name 'Example'.
+ *
+ * \since 1.6.3
+ */
+struct ast_rtp_glue *ast_rtp_instance_get_glue(const char *type);
+
+/*!
+ * \brief Bridge two channels that use RTP instances
+ *
+ * \param c0 First channel part of the bridge
+ * \param c1 Second channel part of the bridge
+ * \param flags Bridging flags
+ * \param fo If a frame needs to be passed up it is stored here
+ * \param rc Channel that passed the above frame up
+ * \param timeoutms How long the channels should be bridged for
+ *
+ * \retval Bridge result
+ *
+ * \note This should only be used by channel drivers in their technology declaration.
+ *
+ * \since 1.6.3
+ */
+enum ast_bridge_result ast_rtp_instance_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
+
+/*!
+ * \brief Get the other RTP instance that an instance is bridged to
+ *
+ * \param instance The RTP instance that we want
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ *
+ * Example usage:
+ *
+ * \code
+ * struct ast_rtp_instance *bridged = ast_rtp_instance_get_bridged(instance0);
+ * \endcode
+ *
+ * This gets the RTP instance that instance0 is bridged to.
+ *
+ * \since 1.6.3
+ */
+struct ast_rtp_instance *ast_rtp_instance_get_bridged(struct ast_rtp_instance *instance);
+
+/*!
+ * \brief Make two channels compatible for early bridging
+ *
+ * \param c0 First channel part of the bridge
+ * \param c1 Second channel part of the bridge
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_instance_early_bridge_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
+
+/*!
+ * \brief Early bridge two channels that use RTP instances
+ *
+ * \param c0 First channel part of the bridge
+ * \param c1 Second channel part of the bridge
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * \note This should only be used by channel drivers in their technology declaration.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
+
+/*!
+ * \brief Initialize RED support on an RTP instance
+ *
+ * \param instance The instance to initialize RED support on
+ * \param buffer_time How long to buffer before sending
+ * \param payloads Payload values
+ * \param generations Number of generations
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_red_init(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations);
+
+/*!
+ * \brief Buffer a frame in an RTP instance for RED
+ *
+ * \param instance The instance to buffer the frame on
+ * \param frame Frame that we want to buffer
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_red_buffer(struct ast_rtp_instance *instance, struct ast_frame *frame);
+
+/*!
+ * \brief Retrieve statistics about an RTP instance
+ *
+ * \param instance Instance to get statistics on
+ * \param stats Structure to put results into
+ * \param stat What statistic(s) to retrieve
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * struct ast_rtp_instance_stats stats;
+ * ast_rtp_instance_get_stats(instance, &stats, AST_RTP_INSTANCE_STAT_ALL);
+ * \endcode
+ *
+ * This retrieves all statistics the underlying RTP engine supports and puts the values into the
+ * stats structure.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat);
+
+/*!
+ * \brief Set standard statistics from an RTP instance on a channel
+ *
+ * \param chan Channel to set the statistics on
+ * \param instance The RTP instance that statistics will be retrieved from
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_set_stats_vars(chan, rtp);
+ * \endcode
+ *
+ * This retrieves standard statistics from the RTP instance rtp and sets it on the channel pointed to
+ * by chan.
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_instance_set_stats_vars(struct ast_channel *chan, struct ast_rtp_instance *instance);
+
+/*!
+ * \brief Retrieve quality statistics about an RTP instance
+ *
+ * \param instance Instance to get statistics on
+ * \param field What quality statistic to retrieve
+ * \param buf What buffer to put the result into
+ * \param size Size of the above buffer
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ *
+ * Example usage:
+ *
+ * \code
+ * char quality[AST_MAX_USER_FIELD];
+ * ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, &buf, sizeof(buf));
+ * \endcode
+ *
+ * This retrieves general quality statistics and places a text representation into the buf pointed to by buf.
+ *
+ * \since 1.6.3
+ */
+char *ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size);
+
+/*!
+ * \brief Request that the underlying RTP engine provide audio frames in a specific format
+ *
+ * \param instance The RTP instance to change read format on
+ * \param format Format that frames are wanted in
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_set_read_format(instance, AST_FORMAT_ULAW);
+ * \endcode
+ *
+ * This requests that the RTP engine provide audio frames in the ULAW format.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_set_read_format(struct ast_rtp_instance *instance, int format);
+
+/*!
+ * \brief Tell underlying RTP engine that audio frames will be provided in a specific format
+ *
+ * \param instance The RTP instance to change write format on
+ * \param format Format that frames will be provided in
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_set_write_format(instance, AST_FORMAT_ULAW);
+ * \endcode
+ *
+ * This tells the underlying RTP engine that audio frames will be provided to it in ULAW format.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_set_write_format(struct ast_rtp_instance *instance, int format);
+
+/*!
+ * \brief Request that the underlying RTP engine make two RTP instances compatible with eachother
+ *
+ * \param chan Our own Asterisk channel
+ * \param instance The first RTP instance
+ * \param peer The peer Asterisk channel
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_make_compatible(instance, peer);
+ * \endcode
+ *
+ * This makes the RTP instance for 'peer' compatible with 'instance' and vice versa.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_make_compatible(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_channel *peer);
+
+/*!
+ * \brief Indicate to the RTP engine that packets are now expected to be sent/received on the RTP instance
+ *
+ * \param instance The RTP instance
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_activate(instance);
+ * \endcode
+ *
+ * This tells the underlying RTP engine of instance that packets will now flow.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_activate(struct ast_rtp_instance *instance);
+
+/*!
+ * \brief Request that the underlying RTP engine send a STUN BIND request
+ *
+ * \param instance The RTP instance
+ * \param suggestion The suggested destination
+ * \param username Optionally a username for the request
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_stun_request(instance, NULL, NULL);
+ * \endcode
+ *
+ * This requests that the RTP engine send a STUN BIND request on the session pointed to by
+ * 'instance'.
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_instance_stun_request(struct ast_rtp_instance *instance, struct sockaddr_in *suggestion, const char *username);
+
+/*!
+ * \brief Set the RTP timeout value
+ *
+ * \param instance The RTP instance
+ * \param timeout Value to set the timeout to
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_set_timeout(instance, 5000);
+ * \endcode
+ *
+ * This sets the RTP timeout value on 'instance' to be 5000.
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_instance_set_timeout(struct ast_rtp_instance *instance, int timeout);
+
+/*!
+ * \brief Set the RTP timeout value for when the instance is on hold
+ *
+ * \param instance The RTP instance
+ * \param timeout Value to set the timeout to
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_set_hold_timeout(instance, 5000);
+ * \endcode
+ *
+ * This sets the RTP hold timeout value on 'instance' to be 5000.
+ *
+ * \since 1.6.3
+ */
+void ast_rtp_instance_set_hold_timeout(struct ast_rtp_instance *instance, int timeout);
+
+/*!
+ * \brief Get the RTP timeout value
+ *
+ * \param instance The RTP instance
+ *
+ * \retval timeout value
+ *
+ * Example usage:
+ *
+ * \code
+ * int timeout = ast_rtp_instance_get_timeout(instance);
+ * \endcode
+ *
+ * This gets the RTP timeout value for the RTP instance pointed to by 'instance'.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_get_timeout(struct ast_rtp_instance *instance);
+
+/*!
+ * \brief Get the RTP timeout value for when an RTP instance is on hold
+ *
+ * \param instance The RTP instance
+ *
+ * \retval timeout value
+ *
+ * Example usage:
+ *
+ * \code
+ * int timeout = ast_rtp_instance_get_hold_timeout(instance);
+ * \endcode
+ *
+ * This gets the RTP hold timeout value for the RTP instance pointed to by 'instance'.
+ *
+ * \since 1.6.3
+ */
+int ast_rtp_instance_get_hold_timeout(struct ast_rtp_instance *instance);
+
+#if defined(__cplusplus) || defined(c_plusplus)
+}
+#endif
+
+#endif /* _ASTERISK_RTP_ENGINE_H */
--- /dev/null
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2008, 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 stun.h
+ * \brief STUN support.
+ *
+ * STUN is defined in RFC 3489.
+ */
+
+#ifndef _ASTERISK_STUN_H
+#define _ASTERISK_STUN_H
+
+#include "asterisk/network.h"
+
+#if defined(__cplusplus) || defined(c_plusplus)
+extern "C" {
+#endif
+
+enum ast_stun_result {
+ AST_STUN_IGNORE = 0,
+ AST_STUN_ACCEPT,
+};
+
+struct stun_attr;
+
+/*! \brief Generic STUN request
+ * send a generic stun request to the server specified.
+ * \param s the socket used to send the request
+ * \param dst the address of the STUN server
+ * \param username if non null, add the username in the request
+ * \param answer if non null, the function waits for a response and
+ * puts here the externally visible address.
+ * \return 0 on success, other values on error.
+ * The interface it may change in the future.
+ */
+int ast_stun_request(int s, struct sockaddr_in *dst, const char *username, struct sockaddr_in *answer);
+
+/*! \brief callback type to be invoked on stun responses. */
+typedef int (stun_cb_f)(struct stun_attr *attr, void *arg);
+
+/*! \brief handle an incoming STUN message.
+ *
+ * Do some basic sanity checks on packet size and content,
+ * try to extract a bit of information, and possibly reply.
+ * At the moment this only processes BIND requests, and returns
+ * the externally visible address of the request.
+ * If a callback is specified, invoke it with the attribute.
+ */
+int ast_stun_handle_packet(int s, struct sockaddr_in *src, unsigned char *data, size_t len, stun_cb_f *stun_cb, void *arg);
+
+#if defined(__cplusplus) || defined(c_plusplus)
+}
+#endif
+
+#endif /* _ASTERISK_STUN_H */
OBJS= tcptls.o io.o sched.o logger.o frame.o loader.o config.o channel.o \
translate.o file.o pbx.o cli.o md5.o term.o heap.o \
ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
- cdr.o tdd.o acl.o rtp.o udptl.o manager.o asterisk.o \
+ cdr.o tdd.o acl.o udptl.o manager.o asterisk.o \
dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \
strcompat.o threadstorage.o dial.o event.o adsistub.o audiohook.o \
astobj2.o hashtab.o global_datastores.o version.o \
features.o taskprocessor.o timing.o datastore.o xml.o xmldoc.o \
- strings.o bridging.o poll.o
+ strings.o bridging.o poll.o rtp_engine.o stun.o
# we need to link in the objects statically, not as a library, because
# otherwise modules will not have them available if none of the static
#include "asterisk/cdr.h"
#include "asterisk/pbx.h"
#include "asterisk/enum.h"
-#include "asterisk/rtp.h"
#include "asterisk/http.h"
#include "asterisk/udptl.h"
#include "asterisk/app.h"
exit(1);
}
- ast_rtp_init();
ast_dsp_init();
ast_udptl_init();
#include "asterisk/manager.h"
#include "asterisk/cdr.h"
#include "asterisk/enum.h"
-#include "asterisk/rtp.h"
#include "asterisk/http.h"
#include "asterisk/lock.h"
#include "asterisk/features.h"
{ "extconfig", read_config_maps },
{ "enum", ast_enum_reload },
{ "manager", reload_manager },
- { "rtp", ast_rtp_reload },
{ "http", ast_http_reload },
{ "logger", logger_reload },
{ "features", ast_features_reload },
+++ /dev/null
-/*
- * 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 Supports RTP and RTCP with Symmetric RTP support for NAT traversal.
- *
- * \author Mark Spencer <markster@digium.com>
- *
- * \note RTP is defined in RFC 3550.
- */
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include <sys/time.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <math.h>
-
-#include "asterisk/rtp.h"
-#include "asterisk/pbx.h"
-#include "asterisk/frame.h"
-#include "asterisk/channel.h"
-#include "asterisk/acl.h"
-#include "asterisk/config.h"
-#include "asterisk/lock.h"
-#include "asterisk/utils.h"
-#include "asterisk/netsock.h"
-#include "asterisk/cli.h"
-#include "asterisk/manager.h"
-#include "asterisk/unaligned.h"
-
-#define MAX_TIMESTAMP_SKEW 640
-
-#define RTP_SEQ_MOD (1<<16) /*!< A sequence number can't be more than 16 bits */
-#define RTCP_DEFAULT_INTERVALMS 5000 /*!< Default milli-seconds between RTCP reports we send */
-#define RTCP_MIN_INTERVALMS 500 /*!< Min milli-seconds between RTCP reports we send */
-#define RTCP_MAX_INTERVALMS 60000 /*!< Max milli-seconds between RTCP reports we send */
-
-#define RTCP_PT_FUR 192
-#define RTCP_PT_SR 200
-#define RTCP_PT_RR 201
-#define RTCP_PT_SDES 202
-#define RTCP_PT_BYE 203
-#define RTCP_PT_APP 204
-
-#define RTP_MTU 1200
-
-#define DEFAULT_DTMF_TIMEOUT 3000 /*!< samples */
-
-static int dtmftimeout = DEFAULT_DTMF_TIMEOUT;
-
-static int rtpstart = 5000; /*!< First port for RTP sessions (set in rtp.conf) */
-static int rtpend = 31000; /*!< Last port for RTP sessions (set in rtp.conf) */
-static int rtpdebug; /*!< Are we debugging? */
-static int rtcpdebug; /*!< Are we debugging RTCP? */
-static int rtcpstats; /*!< Are we debugging RTCP? */
-static int rtcpinterval = RTCP_DEFAULT_INTERVALMS; /*!< Time between rtcp reports in millisecs */
-static int stundebug; /*!< Are we debugging stun? */
-static struct sockaddr_in rtpdebugaddr; /*!< Debug packets to/from this host */
-static struct sockaddr_in rtcpdebugaddr; /*!< Debug RTCP packets to/from this host */
-#ifdef SO_NO_CHECK
-static int nochecksums;
-#endif
-static int strictrtp;
-
-enum strict_rtp_state {
- STRICT_RTP_OPEN = 0, /*! No RTP packets should be dropped, all sources accepted */
- STRICT_RTP_LEARN, /*! Accept next packet as source */
- STRICT_RTP_CLOSED, /*! Drop all RTP packets not coming from source that was learned */
-};
-
-/* Uncomment this to enable more intense native bridging, but note: this is currently buggy */
-/* #define P2P_INTENSE */
-
-/*!
- * \brief Structure representing a RTP session.
- *
- * 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 [...]"
- *
- */
-
-/*! \brief RTP session description */
-struct ast_rtp {
- int s;
- struct ast_frame f;
- unsigned char rawdata[8192 + AST_FRIENDLY_OFFSET];
- unsigned int ssrc; /*!< Synchronization source, RFC 3550, page 10. */
- unsigned int themssrc; /*!< Their SSRC */
- unsigned int rxssrc;
- unsigned int lastts;
- unsigned int lastrxts;
- unsigned int lastividtimestamp;
- unsigned int lastovidtimestamp;
- unsigned int lastitexttimestamp;
- unsigned int lastotexttimestamp;
- unsigned int lasteventseqn;
- int lastrxseqno; /*!< Last received sequence number */
- unsigned short seedrxseqno; /*!< What sequence number did they start with?*/
- unsigned int seedrxts; /*!< What RTP timestamp did they start with? */
- unsigned int rxcount; /*!< How many packets have we received? */
- unsigned int rxoctetcount; /*!< How many octets have we received? should be rxcount *160*/
- unsigned int txcount; /*!< How many packets have we sent? */
- unsigned int txoctetcount; /*!< How many octets have we sent? (txcount*160)*/
- unsigned int cycles; /*!< Shifted count of sequence number cycles */
- double rxjitter; /*!< Interarrival jitter at the moment */
- double rxtransit; /*!< Relative transit time for previous packet */
- int lasttxformat;
- int lastrxformat;
-
- int rtptimeout; /*!< RTP timeout time (negative or zero means disabled, negative value means temporarily disabled) */
- int rtpholdtimeout; /*!< RTP timeout when on hold (negative or zero means disabled, negative value means temporarily disabled). */
- int rtpkeepalive; /*!< Send RTP comfort noice packets for keepalive */
-
- /* DTMF Reception Variables */
- char resp;
- unsigned int lastevent;
- int dtmfcount;
- unsigned int dtmfsamples;
- /* DTMF Transmission Variables */
- unsigned int lastdigitts;
- char sending_digit; /*!< boolean - are we sending digits */
- char send_digit; /*!< digit we are sending */
- int send_payload;
- int send_duration;
- int nat;
- unsigned int flags;
- struct sockaddr_in us; /*!< Socket representation of the local endpoint. */
- struct sockaddr_in them; /*!< Socket representation of the remote endpoint. */
- struct timeval rxcore;
- struct timeval txcore;
- double drxcore; /*!< The double representation of the first received packet */
- struct timeval lastrx; /*!< timeval when we last received a packet */
- struct timeval dtmfmute;
- struct ast_smoother *smoother;
- int *ioid;
- unsigned short seqno; /*!< Sequence number, RFC 3550, page 13. */
- unsigned short rxseqno;
- struct sched_context *sched;
- struct io_context *io;
- void *data;
- ast_rtp_callback callback;
-#ifdef P2P_INTENSE
- ast_mutex_t bridge_lock;
-#endif
- struct rtpPayloadType current_RTP_PT[MAX_RTP_PT];
- int rtp_lookup_code_cache_isAstFormat; /*!< a cache for the result of rtp_lookup_code(): */
- int rtp_lookup_code_cache_code;
- int rtp_lookup_code_cache_result;
- struct ast_rtcp *rtcp;
- struct ast_codec_pref pref;
- struct ast_rtp *bridged; /*!< Who we are Packet bridged to */
-
- enum strict_rtp_state strict_rtp_state; /*!< Current state that strict RTP protection is in */
- struct sockaddr_in strict_rtp_address; /*!< Remote address information for strict RTP purposes */
-
- int set_marker_bit:1; /*!< Whether to set the marker bit or not */
- struct rtp_red *red;
-};
-
-static struct ast_frame *red_t140_to_red(struct rtp_red *red);
-static int red_write(const void *data);
-
-struct rtp_red {
- struct ast_frame t140; /*!< Primary data */
- struct ast_frame t140red; /*!< Redundant t140*/
- unsigned char pt[RED_MAX_GENERATION]; /*!< Payload types for redundancy data */
- unsigned char ts[RED_MAX_GENERATION]; /*!< Time stamps */
- unsigned char len[RED_MAX_GENERATION]; /*!< length of each generation */
- int num_gen; /*!< Number of generations */
- int schedid; /*!< Timer id */
- int ti; /*!< How long to buffer data before send */
- unsigned char t140red_data[64000];
- unsigned char buf_data[64000]; /*!< buffered primary data */
- int hdrlen;
- long int prev_ts;
-};
-
-/* Forward declarations */
-static int ast_rtcp_write(const void *data);
-static void timeval2ntp(struct timeval tv, unsigned int *msw, unsigned int *lsw);
-static int ast_rtcp_write_sr(const void *data);
-static int ast_rtcp_write_rr(const void *data);
-static unsigned int ast_rtcp_calc_interval(struct ast_rtp *rtp);
-static int ast_rtp_senddigit_continuation(struct ast_rtp *rtp);
-int ast_rtp_senddigit_end(struct ast_rtp *rtp, char digit);
-
-#define FLAG_3389_WARNING (1 << 0)
-#define FLAG_NAT_ACTIVE (3 << 1)
-#define FLAG_NAT_INACTIVE (0 << 1)
-#define FLAG_NAT_INACTIVE_NOWARN (1 << 1)
-#define FLAG_HAS_DTMF (1 << 3)
-#define FLAG_P2P_SENT_MARK (1 << 4)
-#define FLAG_P2P_NEED_DTMF (1 << 5)
-#define FLAG_CALLBACK_MODE (1 << 6)
-#define FLAG_DTMF_COMPENSATE (1 << 7)
-#define FLAG_HAS_STUN (1 << 8)
-
-/*!
- * \brief Structure defining an RTCP session.
- *
- * The concept "RTCP session" is not defined in RFC 3550, but since
- * this structure is analogous to ast_rtp, which tracks a RTP session,
- * it is logical to think of this as a RTCP session.
- *
- * RTCP packet is defined on page 9 of RFC 3550.
- *
- */
-struct ast_rtcp {
- int rtcp_info;
- int s; /*!< Socket */
- struct sockaddr_in us; /*!< Socket representation of the local endpoint. */
- struct sockaddr_in them; /*!< Socket representation of the remote endpoint. */
- unsigned int soc; /*!< What they told us */
- unsigned int spc; /*!< What they told us */
- unsigned int themrxlsr; /*!< The middle 32 bits of the NTP timestamp in the last received SR*/
- struct timeval rxlsr; /*!< Time when we got their last SR */
- struct timeval txlsr; /*!< Time when we sent or last SR*/
- unsigned int expected_prior; /*!< no. packets in previous interval */
- unsigned int received_prior; /*!< no. packets received in previous interval */
- int schedid; /*!< Schedid returned from ast_sched_add() to schedule RTCP-transmissions*/
- unsigned int rr_count; /*!< number of RRs we've sent, not including report blocks in SR's */
- unsigned int sr_count; /*!< number of SRs we've sent */
- unsigned int lastsrtxcount; /*!< Transmit packet count when last SR sent */
- double accumulated_transit; /*!< accumulated a-dlsr-lsr */
- double rtt; /*!< Last reported rtt */
- unsigned int reported_jitter; /*!< The contents of their last jitter entry in the RR */
- unsigned int reported_lost; /*!< Reported lost packets in their RR */
- char quality[AST_MAX_USER_FIELD];
- char quality_jitter[AST_MAX_USER_FIELD];
- char quality_loss[AST_MAX_USER_FIELD];
- char quality_rtt[AST_MAX_USER_FIELD];
-
- double reported_maxjitter;
- double reported_minjitter;
- double reported_normdev_jitter;
- double reported_stdev_jitter;
- unsigned int reported_jitter_count;
-
- double reported_maxlost;
- double reported_minlost;
- double reported_normdev_lost;
- double reported_stdev_lost;
-
- double rxlost;
- double maxrxlost;
- double minrxlost;
- double normdev_rxlost;
- double stdev_rxlost;
- unsigned int rxlost_count;
-
- double maxrxjitter;
- double minrxjitter;
- double normdev_rxjitter;
- double stdev_rxjitter;
- unsigned int rxjitter_count;
- double maxrtt;
- double minrtt;
- double normdevrtt;
- double stdevrtt;
- unsigned int rtt_count;
- int sendfur;
-};
-
-/*!
- * \brief STUN support code
- *
- * This code provides some support for doing STUN transactions.
- * Eventually it should be moved elsewhere as other protocols
- * than RTP can benefit from it - e.g. SIP.
- * STUN is described in RFC3489 and it is based on the exchange
- * of UDP packets between a client and one or more servers to
- * determine the externally visible address (and port) of the client
- * once it has gone through the NAT boxes that connect it to the
- * outside.
- * The simplest request packet is just the header defined in
- * struct stun_header, and from the response we may just look at
- * one attribute, STUN_MAPPED_ADDRESS, that we find in the response.
- * By doing more transactions with different server addresses we
- * may determine more about the behaviour of the NAT boxes, of
- * course - the details are in the RFC.
- *
- * All STUN packets start with a simple header made of a type,
- * length (excluding the header) and a 16-byte random transaction id.
- * Following the header we may have zero or more attributes, each
- * structured as a type, length and a value (whose format depends
- * on the type, but often contains addresses).
- * Of course all fields are in network format.
- */
-
-typedef struct { unsigned int id[4]; } __attribute__((packed)) stun_trans_id;
-
-struct stun_header {
- unsigned short msgtype;
- unsigned short msglen;
- stun_trans_id id;
- unsigned char ies[0];
-} __attribute__((packed));
-
-struct stun_attr {
- unsigned short attr;
- unsigned short len;
- unsigned char value[0];
-} __attribute__((packed));
-
-/*
- * The format normally used for addresses carried by STUN messages.
- */
-struct stun_addr {
- unsigned char unused;
- unsigned char family;
- unsigned short port;
- unsigned int addr;
-} __attribute__((packed));
-
-#define STUN_IGNORE (0)
-#define STUN_ACCEPT (1)
-
-/*! \brief STUN message types
- * 'BIND' refers to transactions used to determine the externally
- * visible addresses. 'SEC' refers to transactions used to establish
- * a session key for subsequent requests.
- * 'SEC' functionality is not supported here.
- */
-
-#define STUN_BINDREQ 0x0001
-#define STUN_BINDRESP 0x0101
-#define STUN_BINDERR 0x0111
-#define STUN_SECREQ 0x0002
-#define STUN_SECRESP 0x0102
-#define STUN_SECERR 0x0112
-
-/*! \brief Basic attribute types in stun messages.
- * Messages can also contain custom attributes (codes above 0x7fff)
- */
-#define STUN_MAPPED_ADDRESS 0x0001
-#define STUN_RESPONSE_ADDRESS 0x0002
-#define STUN_CHANGE_REQUEST 0x0003
-#define STUN_SOURCE_ADDRESS 0x0004
-#define STUN_CHANGED_ADDRESS 0x0005
-#define STUN_USERNAME 0x0006
-#define STUN_PASSWORD 0x0007
-#define STUN_MESSAGE_INTEGRITY 0x0008
-#define STUN_ERROR_CODE 0x0009
-#define STUN_UNKNOWN_ATTRIBUTES 0x000a
-#define STUN_REFLECTED_FROM 0x000b
-
-/*! \brief helper function to print message names */
-static const char *stun_msg2str(int msg)
-{
- switch (msg) {
- case STUN_BINDREQ:
- return "Binding Request";
- case STUN_BINDRESP:
- return "Binding Response";
- case STUN_BINDERR:
- return "Binding Error Response";
- case STUN_SECREQ:
- return "Shared Secret Request";
- case STUN_SECRESP:
- return "Shared Secret Response";
- case STUN_SECERR:
- return "Shared Secret Error Response";
- }
- return "Non-RFC3489 Message";
-}
-
-/*! \brief helper function to print attribute names */
-static const char *stun_attr2str(int msg)
-{
- switch (msg) {
- case STUN_MAPPED_ADDRESS:
- return "Mapped Address";
- case STUN_RESPONSE_ADDRESS:
- return "Response Address";
- case STUN_CHANGE_REQUEST:
- return "Change Request";
- case STUN_SOURCE_ADDRESS:
- return "Source Address";
- case STUN_CHANGED_ADDRESS:
- return "Changed Address";
- case STUN_USERNAME:
- return "Username";
- case STUN_PASSWORD:
- return "Password";
- case STUN_MESSAGE_INTEGRITY:
- return "Message Integrity";
- case STUN_ERROR_CODE:
- return "Error Code";
- case STUN_UNKNOWN_ATTRIBUTES:
- return "Unknown Attributes";
- case STUN_REFLECTED_FROM:
- return "Reflected From";
- }
- return "Non-RFC3489 Attribute";
-}
-
-/*! \brief here we store credentials extracted from a message */
-struct stun_state {
- const char *username;
- const char *password;
-};
-
-static int stun_process_attr(struct stun_state *state, struct stun_attr *attr)
-{
- if (stundebug)
- ast_verbose("Found STUN Attribute %s (%04x), length %d\n",
- stun_attr2str(ntohs(attr->attr)), ntohs(attr->attr), ntohs(attr->len));
- switch (ntohs(attr->attr)) {
- case STUN_USERNAME:
- state->username = (const char *) (attr->value);
- break;
- case STUN_PASSWORD:
- state->password = (const char *) (attr->value);
- break;
- default:
- if (stundebug)
- ast_verbose("Ignoring STUN attribute %s (%04x), length %d\n",
- stun_attr2str(ntohs(attr->attr)), ntohs(attr->attr), ntohs(attr->len));
- }
- return 0;
-}
-
-/*! \brief append a string to an STUN message */
-static void append_attr_string(struct stun_attr **attr, int attrval, const char *s, int *len, int *left)
-{
- int size = sizeof(**attr) + strlen(s);
- if (*left > size) {
- (*attr)->attr = htons(attrval);
- (*attr)->len = htons(strlen(s));
- memcpy((*attr)->value, s, strlen(s));
- (*attr) = (struct stun_attr *)((*attr)->value + strlen(s));
- *len += size;
- *left -= size;
- }
-}
-
-/*! \brief append an address to an STUN message */
-static void append_attr_address(struct stun_attr **attr, int attrval, struct sockaddr_in *sock_in, int *len, int *left)
-{
- int size = sizeof(**attr) + 8;
- struct stun_addr *addr;
- if (*left > size) {
- (*attr)->attr = htons(attrval);
- (*attr)->len = htons(8);
- addr = (struct stun_addr *)((*attr)->value);
- addr->unused = 0;
- addr->family = 0x01;
- addr->port = sock_in->sin_port;
- addr->addr = sock_in->sin_addr.s_addr;
- (*attr) = (struct stun_attr *)((*attr)->value + 8);
- *len += size;
- *left -= size;
- }
-}
-
-/*! \brief wrapper to send an STUN message */
-static int stun_send(int s, struct sockaddr_in *dst, struct stun_header *resp)
-{
- return sendto(s, resp, ntohs(resp->msglen) + sizeof(*resp), 0,
- (struct sockaddr *)dst, sizeof(*dst));
-}
-
-/*! \brief helper function to generate a random request id */
-static void stun_req_id(struct stun_header *req)
-{
- int x;
- for (x = 0; x < 4; x++)
- req->id.id[x] = ast_random();
-}
-
-size_t ast_rtp_alloc_size(void)
-{
- return sizeof(struct ast_rtp);
-}
-
-/*! \brief callback type to be invoked on stun responses. */
-typedef int (stun_cb_f)(struct stun_attr *attr, void *arg);
-
-/*! \brief handle an incoming STUN message.
- *
- * Do some basic sanity checks on packet size and content,
- * try to extract a bit of information, and possibly reply.
- * At the moment this only processes BIND requests, and returns
- * the externally visible address of the request.
- * If a callback is specified, invoke it with the attribute.
- */
-static int stun_handle_packet(int s, struct sockaddr_in *src,
- unsigned char *data, size_t len, stun_cb_f *stun_cb, void *arg)
-{
- struct stun_header *hdr = (struct stun_header *)data;
- struct stun_attr *attr;
- struct stun_state st;
- int ret = STUN_IGNORE;
- int x;
-
- /* On entry, 'len' is the length of the udp payload. After the
- * initial checks it becomes the size of unprocessed options,
- * while 'data' is advanced accordingly.
- */
- if (len < sizeof(struct stun_header)) {
- ast_debug(1, "Runt STUN packet (only %d, wanting at least %d)\n", (int) len, (int) sizeof(struct stun_header));
- return -1;
- }
- len -= sizeof(struct stun_header);
- data += sizeof(struct stun_header);
- x = ntohs(hdr->msglen); /* len as advertised in the message */
- if (stundebug)
- ast_verbose("STUN Packet, msg %s (%04x), length: %d\n", stun_msg2str(ntohs(hdr->msgtype)), ntohs(hdr->msgtype), x);
- if (x > len) {
- ast_debug(1, "Scrambled STUN packet length (got %d, expecting %d)\n", x, (int)len);
- } else
- len = x;
- memset(&st, 0, sizeof(st));
- while (len) {
- if (len < sizeof(struct stun_attr)) {
- ast_debug(1, "Runt Attribute (got %d, expecting %d)\n", (int)len, (int) sizeof(struct stun_attr));
- break;
- }
- attr = (struct stun_attr *)data;
- /* compute total attribute length */
- x = ntohs(attr->len) + sizeof(struct stun_attr);
- if (x > len) {
- ast_debug(1, "Inconsistent Attribute (length %d exceeds remaining msg len %d)\n", x, (int)len);
- break;
- }
- if (stun_cb)
- stun_cb(attr, arg);
- if (stun_process_attr(&st, attr)) {
- ast_debug(1, "Failed to handle attribute %s (%04x)\n", stun_attr2str(ntohs(attr->attr)), ntohs(attr->attr));
- break;
- }
- /* Clear attribute id: in case previous entry was a string,
- * this will act as the terminator for the string.
- */
- attr->attr = 0;
- data += x;
- len -= x;
- }
- /* Null terminate any string.
- * XXX NOTE, we write past the size of the buffer passed by the
- * caller, so this is potentially dangerous. The only thing that
- * saves us is that usually we read the incoming message in a
- * much larger buffer in the struct ast_rtp
- */
- *data = '\0';
-
- /* Now prepare to generate a reply, which at the moment is done
- * only for properly formed (len == 0) STUN_BINDREQ messages.
- */
- if (len == 0) {
- unsigned char respdata[1024];
- struct stun_header *resp = (struct stun_header *)respdata;
- int resplen = 0; /* len excluding header */
- int respleft = sizeof(respdata) - sizeof(struct stun_header);
-
- resp->id = hdr->id;
- resp->msgtype = 0;
- resp->msglen = 0;
- attr = (struct stun_attr *)resp->ies;
- switch (ntohs(hdr->msgtype)) {
- case STUN_BINDREQ:
- if (stundebug)
- ast_verbose("STUN Bind Request, username: %s\n",
- st.username ? st.username : "<none>");
- if (st.username)
- append_attr_string(&attr, STUN_USERNAME, st.username, &resplen, &respleft);
- append_attr_address(&attr, STUN_MAPPED_ADDRESS, src, &resplen, &respleft);
- resp->msglen = htons(resplen);
- resp->msgtype = htons(STUN_BINDRESP);
- stun_send(s, src, resp);
- ret = STUN_ACCEPT;
- break;
- default:
- if (stundebug)
- ast_verbose("Dunno what to do with STUN message %04x (%s)\n", ntohs(hdr->msgtype), stun_msg2str(ntohs(hdr->msgtype)));
- }
- }
- return ret;
-}
-
-/*! \brief Extract the STUN_MAPPED_ADDRESS from the stun response.
- * This is used as a callback for stun_handle_response
- * when called from ast_stun_request.
- */
-static int stun_get_mapped(struct stun_attr *attr, void *arg)
-{
- struct stun_addr *addr = (struct stun_addr *)(attr + 1);
- struct sockaddr_in *sa = (struct sockaddr_in *)arg;
-
- if (ntohs(attr->attr) != STUN_MAPPED_ADDRESS || ntohs(attr->len) != 8)
- return 1; /* not us. */
- sa->sin_port = addr->port;
- sa->sin_addr.s_addr = addr->addr;
- return 0;
-}
-
-/*! \brief Generic STUN request
- * Send a generic stun request to the server specified,
- * possibly waiting for a reply and filling the 'reply' field with
- * the externally visible address. Note that in this case the request
- * will be blocking.
- * (Note, the interface may change slightly in the future).
- *
- * \param s the socket used to send the request
- * \param dst the address of the STUN server
- * \param username if non null, add the username in the request
- * \param answer if non null, the function waits for a response and
- * puts here the externally visible address.
- * \return 0 on success, other values on error.
- */
-int ast_stun_request(int s, struct sockaddr_in *dst,
- const char *username, struct sockaddr_in *answer)
-{
- struct stun_header *req;
- unsigned char reqdata[1024];
- int reqlen, reqleft;
- struct stun_attr *attr;
- int res = 0;
- int retry;
-
- req = (struct stun_header *)reqdata;
- stun_req_id(req);
- reqlen = 0;
- reqleft = sizeof(reqdata) - sizeof(struct stun_header);
- req->msgtype = 0;
- req->msglen = 0;
- attr = (struct stun_attr *)req->ies;
- if (username)
- append_attr_string(&attr, STUN_USERNAME, username, &reqlen, &reqleft);
- req->msglen = htons(reqlen);
- req->msgtype = htons(STUN_BINDREQ);
- for (retry = 0; retry < 3; retry++) { /* XXX make retries configurable */
- /* send request, possibly wait for reply */
- unsigned char reply_buf[1024];
- fd_set rfds;
- struct timeval to = { 3, 0 }; /* timeout, make it configurable */
- struct sockaddr_in src;
- socklen_t srclen;
-
- res = stun_send(s, dst, req);
- if (res < 0) {
- ast_log(LOG_WARNING, "ast_stun_request send #%d failed error %d, retry\n",
- retry, res);
- continue;
- }
- if (answer == NULL)
- break;
- FD_ZERO(&rfds);
- FD_SET(s, &rfds);
- res = ast_select(s + 1, &rfds, NULL, NULL, &to);
- if (res <= 0) /* timeout or error */
- continue;
- memset(&src, '\0', sizeof(src));
- srclen = sizeof(src);
- /* XXX pass -1 in the size, because stun_handle_packet might
- * write past the end of the buffer.
- */
- res = recvfrom(s, reply_buf, sizeof(reply_buf) - 1,
- 0, (struct sockaddr *)&src, &srclen);
- if (res < 0) {
- ast_log(LOG_WARNING, "ast_stun_request recvfrom #%d failed error %d, retry\n",
- retry, res);
- continue;
- }
- memset(answer, '\0', sizeof(struct sockaddr_in));
- stun_handle_packet(s, &src, reply_buf, res,
- stun_get_mapped, answer);
- res = 0; /* signal regular exit */
- break;
- }
- return res;
-}
-
-/*! \brief send a STUN BIND request to the given destination.
- * Optionally, add a username if specified.
- */
-void ast_rtp_stun_request(struct ast_rtp *rtp, struct sockaddr_in *suggestion, const char *username)
-{
- ast_stun_request(rtp->s, suggestion, username, NULL);
-}
-
-/*! \brief List of current sessions */
-static AST_RWLIST_HEAD_STATIC(protos, ast_rtp_protocol);
-
-static void timeval2ntp(struct timeval when, unsigned int *msw, unsigned int *lsw)
-{
- unsigned int sec, usec, frac;
- sec = when.tv_sec + 2208988800u; /* Sec between 1900 and 1970 */
- usec = when.tv_usec;
- frac = (usec << 12) + (usec << 8) - ((usec * 3650) >> 6);
- *msw = sec;
- *lsw = frac;
-}
-
-int ast_rtp_fd(struct ast_rtp *rtp)
-{
- return rtp->s;
-}
-
-int ast_rtcp_fd(struct ast_rtp *rtp)
-{
- if (rtp->rtcp)
- return rtp->rtcp->s;
- return -1;
-}
-
-unsigned int ast_rtcp_calc_interval(struct ast_rtp *rtp)
-{
- unsigned int interval;
- /*! \todo XXX Do a more reasonable calculation on this one
- * Look in RFC 3550 Section A.7 for an example*/
- interval = rtcpinterval;
- return interval;
-}
-
-/* \brief Put RTP timeout timers on hold during another transaction, like T.38 */
-void ast_rtp_set_rtptimers_onhold(struct ast_rtp *rtp)
-{
- rtp->rtptimeout = (-1) * rtp->rtptimeout;
- rtp->rtpholdtimeout = (-1) * rtp->rtpholdtimeout;
-}
-
-/*! \brief Set rtp timeout */
-void ast_rtp_set_rtptimeout(struct ast_rtp *rtp, int timeout)
-{
- rtp->rtptimeout = timeout;
-}
-
-/*! \brief Set rtp hold timeout */
-void ast_rtp_set_rtpholdtimeout(struct ast_rtp *rtp, int timeout)
-{
- rtp->rtpholdtimeout = timeout;
-}
-
-/*! \brief set RTP keepalive interval */
-void ast_rtp_set_rtpkeepalive(struct ast_rtp *rtp, int period)
-{
- rtp->rtpkeepalive = period;
-}
-
-/*! \brief Get rtp timeout */
-int ast_rtp_get_rtptimeout(struct ast_rtp *rtp)
-{
- if (rtp->rtptimeout < 0) /* We're not checking, but remembering the setting (during T.38 transmission) */
- return 0;
- return rtp->rtptimeout;
-}
-
-/*! \brief Get rtp hold timeout */
-int ast_rtp_get_rtpholdtimeout(struct ast_rtp *rtp)
-{
- if (rtp->rtptimeout < 0) /* We're not checking, but remembering the setting (during T.38 transmission) */
- return 0;
- return rtp->rtpholdtimeout;
-}
-
-/*! \brief Get RTP keepalive interval */
-int ast_rtp_get_rtpkeepalive(struct ast_rtp *rtp)
-{
- return rtp->rtpkeepalive;
-}
-
-void ast_rtp_set_data(struct ast_rtp *rtp, void *data)
-{
- rtp->data = data;
-}
-
-void ast_rtp_set_callback(struct ast_rtp *rtp, ast_rtp_callback callback)
-{
- rtp->callback = callback;
-}
-
-void ast_rtp_setnat(struct ast_rtp *rtp, int nat)
-{
- rtp->nat = nat;
-}
-
-int ast_rtp_getnat(struct ast_rtp *rtp)
-{
- return ast_test_flag(rtp, FLAG_NAT_ACTIVE);
-}
-
-void ast_rtp_setdtmf(struct ast_rtp *rtp, int dtmf)
-{
- ast_set2_flag(rtp, dtmf ? 1 : 0, FLAG_HAS_DTMF);
-}
-
-void ast_rtp_setdtmfcompensate(struct ast_rtp *rtp, int compensate)
-{
- ast_set2_flag(rtp, compensate ? 1 : 0, FLAG_DTMF_COMPENSATE);
-}
-
-void ast_rtp_setstun(struct ast_rtp *rtp, int stun_enable)
-{
- ast_set2_flag(rtp, stun_enable ? 1 : 0, FLAG_HAS_STUN);
-}
-
-static void rtp_bridge_lock(struct ast_rtp *rtp)
-{
-#ifdef P2P_INTENSE
- ast_mutex_lock(&rtp->bridge_lock);
-#endif
- return;
-}
-
-static void rtp_bridge_unlock(struct ast_rtp *rtp)
-{
-#ifdef P2P_INTENSE
- ast_mutex_unlock(&rtp->bridge_lock);
-#endif
- return;
-}
-
-/*! \brief Calculate normal deviation */
-static double normdev_compute(double normdev, double sample, unsigned int sample_count)
-{
- normdev = normdev * sample_count + sample;
- sample_count++;
-
- return normdev / sample_count;
-}
-
-static double stddev_compute(double stddev, double sample, double normdev, double normdev_curent, unsigned int sample_count)
-{
-/*
- for the formula check http://www.cs.umd.edu/~austinjp/constSD.pdf
- return sqrt( (sample_count*pow(stddev,2) + sample_count*pow((sample-normdev)/(sample_count+1),2) + pow(sample-normdev_curent,2)) / (sample_count+1));
- we can compute the sigma^2 and that way we would have to do the sqrt only 1 time at the end and would save another pow 2 compute
- optimized formula
-*/
-#define SQUARE(x) ((x) * (x))
-
- stddev = sample_count * stddev;
- sample_count++;
-
- return stddev +
- ( sample_count * SQUARE( (sample - normdev) / sample_count ) ) +
- ( SQUARE(sample - normdev_curent) / sample_count );
-
-#undef SQUARE
-}
-
-static struct ast_frame *send_dtmf(struct ast_rtp *rtp, enum ast_frame_type type)
-{
- if (((ast_test_flag(rtp, FLAG_DTMF_COMPENSATE) && type == AST_FRAME_DTMF_END) ||
- (type == AST_FRAME_DTMF_BEGIN)) && ast_tvcmp(ast_tvnow(), rtp->dtmfmute) < 0) {
- ast_debug(1, "Ignore potential DTMF echo from '%s'\n", ast_inet_ntoa(rtp->them.sin_addr));
- rtp->resp = 0;
- rtp->dtmfsamples = 0;
- return &ast_null_frame;
- }
- ast_debug(1, "Sending dtmf: %d (%c), at %s\n", rtp->resp, rtp->resp, ast_inet_ntoa(rtp->them.sin_addr));
- if (rtp->resp == 'X') {
- rtp->f.frametype = AST_FRAME_CONTROL;
- rtp->f.subclass = AST_CONTROL_FLASH;
- } else {
- rtp->f.frametype = type;
- rtp->f.subclass = rtp->resp;
- }
- rtp->f.datalen = 0;
- rtp->f.samples = 0;
- rtp->f.mallocd = 0;
- rtp->f.src = "RTP";
- return &rtp->f;
-
-}
-
-static inline int rtp_debug_test_addr(struct sockaddr_in *addr)
-{
- if (rtpdebug == 0)
- return 0;
- if (rtpdebugaddr.sin_addr.s_addr) {
- if (((ntohs(rtpdebugaddr.sin_port) != 0)
- && (rtpdebugaddr.sin_port != addr->sin_port))
- || (rtpdebugaddr.sin_addr.s_addr != addr->sin_addr.s_addr))
- return 0;
- }
- return 1;
-}
-
-static inline int rtcp_debug_test_addr(struct sockaddr_in *addr)
-{
- if (rtcpdebug == 0)
- return 0;
- if (rtcpdebugaddr.sin_addr.s_addr) {
- if (((ntohs(rtcpdebugaddr.sin_port) != 0)
- && (rtcpdebugaddr.sin_port != addr->sin_port))
- || (rtcpdebugaddr.sin_addr.s_addr != addr->sin_addr.s_addr))
- return 0;
- }
- return 1;
-}
-
-
-static struct ast_frame *process_cisco_dtmf(struct ast_rtp *rtp, unsigned char *data, int len)
-{
- unsigned int event;
- char resp = 0;
- struct ast_frame *f = NULL;
- unsigned char seq;
- unsigned int flags;
- unsigned int power;
-
- /* We should have at least 4 bytes in RTP data */
- if (len < 4)
- return f;
-
- /* The format of Cisco RTP DTMF packet looks like next:
- +0 - sequence number of DTMF RTP packet (begins from 1,
- wrapped to 0)
- +1 - set of flags
- +1 (bit 0) - flaps by different DTMF digits delimited by audio
- or repeated digit without audio???
- +2 (+4,+6,...) - power level? (rises from 0 to 32 at begin of tone
- then falls to 0 at its end)
- +3 (+5,+7,...) - detected DTMF digit (0..9,*,#,A-D,...)
- Repeated DTMF information (bytes 4/5, 6/7) is history shifted right
- by each new packet and thus provides some redudancy.
-