mirror of
https://github.com/asterisk/asterisk.git
synced 2026-07-27 16:07:15 -07:00
Merge in the RTP engine API.
This API provides a generic way for multiple RTP stacks to be integrated into Asterisk. Right now there is only one present, res_rtp_asterisk, which is the existing Asterisk RTP stack. Functionality wise this commit performs the same as previously. API documentation can be viewed in the rtp_engine.h header file. Review: http://reviewboard.digium.com/r/209/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@186078 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
+5
-1
@@ -20,7 +20,11 @@
|
||||
|
||||
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:
|
||||
|
||||
|
||||
+7
-3
@@ -54,7 +54,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#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"
|
||||
@@ -745,7 +745,9 @@ static void do_forward(struct chanlist *o,
|
||||
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 ? */
|
||||
@@ -1745,7 +1747,9 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
|
||||
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);
|
||||
|
||||
@@ -52,7 +52,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#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"
|
||||
|
||||
@@ -39,7 +39,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#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"
|
||||
|
||||
+46
-49
@@ -52,7 +52,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#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"
|
||||
@@ -112,8 +113,8 @@ struct gtalk_pvt {
|
||||
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 */
|
||||
@@ -183,11 +184,6 @@ static int gtalk_sendhtml(struct ast_channel *ast, int subclass, const char *dat
|
||||
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 = {
|
||||
@@ -197,7 +193,7 @@ 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,
|
||||
@@ -216,14 +212,6 @@ static struct sched_context *sched; /*!< The scheduling context */
|
||||
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"),
|
||||
@@ -371,7 +359,7 @@ static int add_codec_to_answer(const struct gtalk_pvt *p, int codec, iks *dcodec
|
||||
iks_insert_node(dcodecs, payload_gsm);
|
||||
res++;
|
||||
}
|
||||
ast_rtp_lookup_code(p->rtp, 1, codec);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -523,18 +511,19 @@ static int gtalk_answer(struct ast_channel *ast)
|
||||
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);
|
||||
|
||||
@@ -547,7 +536,7 @@ static int gtalk_get_codec(struct ast_channel *chan)
|
||||
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;
|
||||
|
||||
@@ -567,6 +556,13 @@ static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, str
|
||||
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;
|
||||
@@ -617,13 +613,13 @@ static int gtalk_is_answered(struct gtalk *client, ikspak *pak)
|
||||
/* 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 */
|
||||
@@ -810,7 +806,7 @@ static int gtalk_create_candidates(struct gtalk *client, struct gtalk_pvt *p, ch
|
||||
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.");
|
||||
@@ -951,8 +947,9 @@ static struct gtalk_pvt *gtalk_alloc(struct gtalk *client, const char *us, const
|
||||
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)
|
||||
@@ -1014,20 +1011,20 @@ static struct ast_channel *gtalk_new(struct gtalk *client, struct gtalk_pvt *i,
|
||||
|
||||
/* 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;
|
||||
@@ -1142,9 +1139,9 @@ static void gtalk_free_pvt(struct gtalk *client, struct gtalk_pvt *p)
|
||||
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);
|
||||
}
|
||||
@@ -1207,13 +1204,13 @@ static int gtalk_newcall(struct gtalk *client, ikspak *pak)
|
||||
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);
|
||||
|
||||
@@ -1277,16 +1274,16 @@ static int gtalk_update_stun(struct gtalk *client, struct gtalk_pvt *p)
|
||||
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);
|
||||
@@ -1387,7 +1384,7 @@ static struct ast_frame *gtalk_rtp_read(struct ast_channel *ast, struct gtalk_pv
|
||||
|
||||
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 */
|
||||
@@ -1438,7 +1435,7 @@ static int gtalk_write(struct ast_channel *ast, struct ast_frame *frame)
|
||||
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);
|
||||
}
|
||||
@@ -1447,7 +1444,7 @@ static int gtalk_write(struct ast_channel *ast, struct ast_frame *frame)
|
||||
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);
|
||||
}
|
||||
@@ -2062,7 +2059,7 @@ static int load_module(void)
|
||||
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 */
|
||||
@@ -2086,7 +2083,7 @@ static int unload_module(void)
|
||||
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 */
|
||||
|
||||
+49
-56
@@ -76,7 +76,7 @@ extern "C" {
|
||||
#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"
|
||||
@@ -161,7 +161,7 @@ struct oh323_pvt {
|
||||
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 */
|
||||
@@ -254,7 +254,7 @@ static const struct ast_channel_tech oh323_tech = {
|
||||
.write = oh323_write,
|
||||
.indicate = oh323_indicate,
|
||||
.fixup = oh323_fixup,
|
||||
.bridge = ast_rtp_bridge,
|
||||
.bridge = ast_rtp_instance_bridge,
|
||||
};
|
||||
|
||||
static const char* redirectingreason2str(int redirectingreason)
|
||||
@@ -381,8 +381,8 @@ static void __oh323_update_info(struct ast_channel *c, struct oh323_pvt *pvt)
|
||||
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;
|
||||
@@ -444,7 +444,7 @@ static void __oh323_destroy(struct oh323_pvt *pvt)
|
||||
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 */
|
||||
@@ -510,7 +510,7 @@ static int oh323_digit_begin(struct ast_channel *c, char digit)
|
||||
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 */
|
||||
@@ -549,7 +549,7 @@ static int oh323_digit_end(struct ast_channel *c, char digit, unsigned int durat
|
||||
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 */
|
||||
@@ -747,11 +747,11 @@ static struct ast_frame *oh323_rtp_read(struct oh323_pvt *pvt)
|
||||
|
||||
/* 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;
|
||||
@@ -808,7 +808,7 @@ static struct ast_frame *oh323_read(struct ast_channel *c)
|
||||
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;
|
||||
@@ -842,7 +842,7 @@ static int oh323_write(struct ast_channel *c, struct ast_frame *frame)
|
||||
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);
|
||||
}
|
||||
@@ -910,7 +910,7 @@ static int oh323_indicate(struct ast_channel *c, int condition, const void *data
|
||||
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:
|
||||
@@ -946,17 +946,17 @@ static int oh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
|
||||
|
||||
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));
|
||||
@@ -965,24 +965,24 @@ static int __oh323_rtp_create(struct oh323_pvt *pvt)
|
||||
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
|
||||
@@ -1028,13 +1028,13 @@ static struct ast_channel *__oh323_new(struct oh323_pvt *pvt, int state, const c
|
||||
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
|
||||
@@ -1112,7 +1112,7 @@ static struct oh323_pvt *oh323_alloc(int callid)
|
||||
}
|
||||
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;
|
||||
}
|
||||
@@ -1912,7 +1912,7 @@ static struct rtp_info *external_rtp_create(unsigned call_reference, const char
|
||||
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));
|
||||
@@ -1931,7 +1931,6 @@ static void setup_rtp_connection(unsigned call_reference, const char *remoteIp,
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -1953,7 +1952,7 @@ static void setup_rtp_connection(unsigned call_reference, const char *remoteIp,
|
||||
__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;
|
||||
@@ -1962,13 +1961,13 @@ static void setup_rtp_connection(unsigned call_reference, const char *remoteIp,
|
||||
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;
|
||||
@@ -1978,7 +1977,7 @@ static void setup_rtp_connection(unsigned call_reference, const char *remoteIp,
|
||||
/* 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) {
|
||||
@@ -2359,7 +2358,7 @@ static void cleanup_connection(unsigned call_reference, const char *call_token)
|
||||
}
|
||||
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 */
|
||||
@@ -2421,7 +2420,7 @@ static void set_dtmf_payload(unsigned call_reference, const char *token, int pay
|
||||
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);
|
||||
@@ -2452,7 +2451,7 @@ static void set_peer_capabilities(unsigned call_reference, const char *token, in
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
@@ -3113,19 +3112,19 @@ static int reload(void)
|
||||
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);
|
||||
@@ -3133,11 +3132,6 @@ static enum ast_rtp_get_result oh323_get_rtp_peer(struct ast_channel *chan, stru
|
||||
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) {
|
||||
@@ -3165,7 +3159,7 @@ static char *convertcap(int 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;
|
||||
@@ -3183,19 +3177,18 @@ static int oh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, str
|
||||
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)
|
||||
@@ -3250,7 +3243,7 @@ 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,
|
||||
@@ -3271,7 +3264,7 @@ static enum ast_module_load_result load_module(void)
|
||||
/* 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();
|
||||
@@ -3310,7 +3303,7 @@ static int unload_module(void)
|
||||
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 */
|
||||
|
||||
+36
-43
@@ -53,7 +53,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#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"
|
||||
@@ -112,9 +112,9 @@ struct jingle_pvt {
|
||||
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 */
|
||||
@@ -183,11 +183,6 @@ static int jingle_sendhtml(struct ast_channel *ast, int subclass, const char *da
|
||||
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 = {
|
||||
@@ -197,7 +192,7 @@ 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,
|
||||
@@ -216,15 +211,6 @@ static struct sched_context *sched; /*!< The scheduling context */
|
||||
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"),
|
||||
@@ -304,7 +290,6 @@ static void add_codec_to_answer(const struct jingle_pvt *p, int codec, iks *dcod
|
||||
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)
|
||||
@@ -398,18 +383,19 @@ static int jingle_answer(struct ast_channel *ast)
|
||||
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);
|
||||
|
||||
@@ -422,7 +408,7 @@ static int jingle_get_codec(struct ast_channel *chan)
|
||||
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;
|
||||
|
||||
@@ -442,6 +428,13 @@ static int jingle_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, st
|
||||
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;
|
||||
@@ -621,7 +614,7 @@ static int jingle_create_candidates(struct jingle *client, struct jingle_pvt *p,
|
||||
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 */
|
||||
@@ -779,7 +772,7 @@ static struct jingle_pvt *jingle_alloc(struct jingle *client, const char *from,
|
||||
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");
|
||||
@@ -825,18 +818,18 @@ static struct ast_channel *jingle_new(struct jingle *client, struct jingle_pvt *
|
||||
|
||||
/* 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;
|
||||
@@ -942,9 +935,9 @@ static void jingle_free_pvt(struct jingle *client, struct jingle_pvt *p)
|
||||
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);
|
||||
}
|
||||
@@ -1009,8 +1002,8 @@ static int jingle_newcall(struct jingle *client, ikspak *pak)
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1025,8 +1018,8 @@ static int jingle_newcall(struct jingle *client, ikspak *pak)
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1079,7 +1072,7 @@ static int jingle_update_stun(struct jingle *client, struct jingle_pvt *p)
|
||||
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;
|
||||
@@ -1169,7 +1162,7 @@ static struct ast_frame *jingle_rtp_read(struct ast_channel *ast, struct jingle_
|
||||
|
||||
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 */
|
||||
@@ -1220,7 +1213,7 @@ static int jingle_write(struct ast_channel *ast, struct ast_frame *frame)
|
||||
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);
|
||||
}
|
||||
@@ -1229,7 +1222,7 @@ static int jingle_write(struct ast_channel *ast, struct ast_frame *frame)
|
||||
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);
|
||||
}
|
||||
@@ -1879,7 +1872,7 @@ static int load_module(void)
|
||||
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)) {
|
||||
@@ -1902,7 +1895,7 @@ static int unload_module(void)
|
||||
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 */
|
||||
|
||||
@@ -39,7 +39,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#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"
|
||||
|
||||
+45
-49
@@ -52,7 +52,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#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"
|
||||
@@ -282,7 +282,7 @@ struct mgcp_subchannel {
|
||||
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 */
|
||||
@@ -408,7 +408,7 @@ static int transmit_response(struct mgcp_subchannel *sub, char *msg, struct mgcp
|
||||
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);
|
||||
@@ -447,7 +447,7 @@ static const struct ast_channel_tech mgcp_tech = {
|
||||
.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)
|
||||
@@ -503,7 +503,7 @@ static int unalloc_sub(struct mgcp_subchannel *sub)
|
||||
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 */
|
||||
@@ -1003,7 +1003,7 @@ static int mgcp_hangup(struct ast_channel *ast)
|
||||
/* 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;
|
||||
}
|
||||
|
||||
@@ -1203,7 +1203,7 @@ static struct ast_frame *mgcp_rtp_read(struct mgcp_subchannel *sub)
|
||||
/* 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;
|
||||
@@ -1261,7 +1261,7 @@ static int mgcp_write(struct ast_channel *ast, struct ast_frame *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);
|
||||
@@ -1297,7 +1297,7 @@ static int mgcp_senddigit_begin(struct ast_channel *ast, char digit)
|
||||
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);
|
||||
}
|
||||
@@ -1324,7 +1324,7 @@ static int mgcp_senddigit_end(struct ast_channel *ast, char digit, unsigned int
|
||||
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);
|
||||
}
|
||||
@@ -1453,7 +1453,7 @@ static int mgcp_indicate(struct ast_channel *ast, int ind, const void *data, siz
|
||||
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, "");
|
||||
@@ -1481,7 +1481,7 @@ static struct ast_channel *mgcp_new(struct mgcp_subchannel *sub, int state)
|
||||
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);
|
||||
@@ -1874,12 +1874,12 @@ static int process_sdp(struct mgcp_subchannel *sub, struct mgcp_request *req)
|
||||
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) {
|
||||
@@ -1888,7 +1888,7 @@ static int process_sdp(struct mgcp_subchannel *sub, struct mgcp_request *req)
|
||||
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;
|
||||
}
|
||||
@@ -1901,11 +1901,11 @@ static int process_sdp(struct mgcp_subchannel *sub, struct mgcp_request *req)
|
||||
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",
|
||||
@@ -2043,7 +2043,7 @@ static int transmit_response(struct mgcp_subchannel *sub, char *msg, struct mgcp
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
@@ -2066,9 +2066,9 @@ static int add_sdp(struct mgcp_request *resp, struct mgcp_subchannel *sub, struc
|
||||
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;
|
||||
@@ -2094,11 +2094,11 @@ static int add_sdp(struct mgcp_request *resp, struct mgcp_subchannel *sub, struc
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -2108,11 +2108,11 @@ static int add_sdp(struct mgcp_request *resp, struct mgcp_subchannel *sub, struc
|
||||
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,
|
||||
@@ -2136,7 +2136,7 @@ static int add_sdp(struct mgcp_request *resp, struct mgcp_subchannel *sub, struc
|
||||
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];
|
||||
@@ -2147,13 +2147,13 @@ static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -2172,7 +2172,7 @@ static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp
|
||||
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];
|
||||
@@ -2183,7 +2183,7 @@ static int transmit_connect_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -2611,21 +2611,17 @@ static void start_rtp(struct mgcp_subchannel *sub)
|
||||
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 */
|
||||
@@ -3940,22 +3936,22 @@ static struct mgcp_gateway *build_gateway(char *cat, struct ast_variable *v)
|
||||
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;
|
||||
@@ -3967,10 +3963,10 @@ static int mgcp_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, stru
|
||||
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)
|
||||
@@ -3984,7 +3980,7 @@ 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));
|
||||
@@ -4276,7 +4272,7 @@ static int load_module(void)
|
||||
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 */
|
||||
@@ -4379,7 +4375,7 @@ static int unload_module(void)
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
+545
-525
File diff suppressed because it is too large
Load Diff
+58
-49
@@ -49,7 +49,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#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"
|
||||
@@ -1111,8 +1111,8 @@ static int matchdigittimeout = 3000;
|
||||
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;
|
||||
@@ -1347,7 +1347,7 @@ static const struct ast_channel_tech skinny_tech = {
|
||||
.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);
|
||||
@@ -2557,46 +2557,48 @@ static void mwi_event_cb(const struct ast_event *event, void *userdata)
|
||||
/* 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);
|
||||
@@ -2605,7 +2607,7 @@ static enum ast_rtp_get_result skinny_get_rtp_peer(struct ast_channel *c, struct
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -2630,7 +2632,7 @@ static int skinny_set_rtp_peer(struct ast_channel *c, struct ast_rtp *rtp, struc
|
||||
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)))
|
||||
@@ -2654,7 +2656,7 @@ static int skinny_set_rtp_peer(struct ast_channel *c, struct ast_rtp *rtp, struc
|
||||
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 {
|
||||
@@ -2675,11 +2677,11 @@ static int skinny_set_rtp_peer(struct ast_channel *c, struct ast_rtp *rtp, struc
|
||||
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)
|
||||
@@ -3559,29 +3561,36 @@ static void start_rtp(struct skinny_subchannel *sub)
|
||||
|
||||
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);
|
||||
|
||||
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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
sub->vrtp = ast_rtp_instance_new(NULL, sched, &bindaddr, NULL);
|
||||
|
||||
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_prop(sub->rtp, AST_RTP_PROPERTY_RTCP, 1);
|
||||
}
|
||||
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_prop(sub->vrtp, AST_RTP_PROPERTY_RTCP, 1);
|
||||
}
|
||||
|
||||
if (sub->rtp && sub->owner) {
|
||||
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_instance_fd(sub->vrtp, 0));
|
||||
ast_channel_set_fd(sub->owner, 3, ast_rtp_instance_fd(sub->vrtp, 1));
|
||||
}
|
||||
if (sub->rtp) {
|
||||
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_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);
|
||||
@@ -3852,7 +3861,7 @@ static int skinny_hangup(struct ast_channel *ast)
|
||||
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);
|
||||
@@ -3913,16 +3922,16 @@ static struct ast_frame *skinny_rtp_read(struct skinny_subchannel *sub)
|
||||
|
||||
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:
|
||||
@@ -3979,7 +3988,7 @@ static int skinny_write(struct ast_channel *ast, struct ast_frame *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);
|
||||
}
|
||||
@@ -4253,7 +4262,7 @@ static int skinny_indicate(struct ast_channel *ast, int ind, const void *data, s
|
||||
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);
|
||||
@@ -4312,7 +4321,7 @@ static struct ast_channel *skinny_new(struct skinny_line *l, int state)
|
||||
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;
|
||||
@@ -5537,8 +5546,8 @@ static int handle_open_receive_channel_ack_message(struct skinny_req *req, struc
|
||||
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;
|
||||
@@ -7289,7 +7298,7 @@ static int load_module(void)
|
||||
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,
|
||||
@@ -7323,7 +7332,7 @@ static int unload_module(void)
|
||||
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));
|
||||
|
||||
|
||||
+32
-65
@@ -60,7 +60,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#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"
|
||||
@@ -365,7 +365,7 @@ struct unistim_subchannel {
|
||||
/*! Unistim line */
|
||||
struct unistim_line *parent;
|
||||
/*! RTP handle */
|
||||
struct ast_rtp *rtp;
|
||||
struct ast_rtp_instance *rtp;
|
||||
int alreadygone;
|
||||
char ringvolume;
|
||||
char ringstyle;
|
||||
@@ -711,7 +711,7 @@ static const struct ast_channel_tech unistim_tech = {
|
||||
.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)
|
||||
@@ -1854,7 +1854,7 @@ static void cancel_dial(struct unistimsession *pte)
|
||||
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)
|
||||
@@ -2056,30 +2056,29 @@ static void start_rtp(struct unistim_subchannel *sub)
|
||||
/* 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);
|
||||
@@ -2091,7 +2090,7 @@ static void start_rtp(struct unistim_subchannel *sub)
|
||||
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 */
|
||||
@@ -3724,7 +3723,7 @@ static int unistim_hangup(struct ast_channel *ast)
|
||||
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;
|
||||
@@ -3769,7 +3768,7 @@ static int unistim_hangup(struct ast_channel *ast)
|
||||
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;
|
||||
@@ -3794,7 +3793,7 @@ static int unistim_hangup(struct ast_channel *ast)
|
||||
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");
|
||||
@@ -3921,10 +3920,10 @@ static struct ast_frame *unistim_rtp_read(const struct ast_channel *ast,
|
||||
|
||||
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;
|
||||
@@ -3990,7 +3989,7 @@ static int unistim_write(struct ast_channel *ast, struct ast_frame *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);
|
||||
}
|
||||
@@ -4455,8 +4454,8 @@ static struct ast_channel *unistim_new(struct unistim_subchannel *sub, int state
|
||||
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);
|
||||
@@ -5526,51 +5525,19 @@ static int reload_config(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static enum ast_rtp_get_result unistim_get_vrtp_peer(struct ast_channel *chan,
|
||||
struct ast_rtp **rtp)
|
||||
static enum ast_rtp_glue_result unistim_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
|
||||
{
|
||||
return AST_RTP_TRY_NATIVE;
|
||||
struct unistim_subchannel *sub = chan->tech_pvt;
|
||||
|
||||
ao2_ref(sub->rtp, +1);
|
||||
*instance = sub->rtp;
|
||||
|
||||
return AST_RTP_GLUE_RESULT_LOCAL;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
struct unistim_subchannel *sub;
|
||||
|
||||
if (unistimdebug)
|
||||
ast_verb(0, "unistim_set_rtp_peer called\n");
|
||||
|
||||
sub = chan->tech_pvt;
|
||||
|
||||
if (sub)
|
||||
return 0;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
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 ---*/
|
||||
@@ -5603,7 +5570,7 @@ int load_module(void)
|
||||
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));
|
||||
|
||||
@@ -5634,7 +5601,7 @@ static int unload_module(void)
|
||||
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)) {
|
||||
|
||||
@@ -292,6 +292,8 @@ srvlookup=yes ; Enable DNS SRV lookups on outbound calls
|
||||
;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
|
||||
|
||||
@@ -41,6 +41,7 @@ int ast_tps_init(void); /*!< Provided by taskprocessor.c */
|
||||
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.
|
||||
|
||||
@@ -1,416 +0,0 @@
|
||||
/*
|
||||
* 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 */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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 */
|
||||
+2
-2
@@ -20,7 +20,7 @@ include $(ASTTOPDIR)/Makefile.moddir_rules
|
||||
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 \
|
||||
@@ -29,7 +29,7 @@ OBJS= tcptls.o io.o sched.o logger.o frame.o loader.o config.o channel.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
|
||||
|
||||
@@ -120,7 +120,6 @@ int daemon(int, int); /* defined in libresolv of all places */
|
||||
#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"
|
||||
@@ -3579,7 +3578,6 @@ int main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ast_rtp_init();
|
||||
ast_dsp_init();
|
||||
ast_udptl_init();
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#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"
|
||||
@@ -243,7 +242,6 @@ static struct reload_classes {
|
||||
{ "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 },
|
||||
|
||||
-4865
File diff suppressed because it is too large
Load Diff
+1572
File diff suppressed because it is too large
Load Diff
+475
@@ -0,0 +1,475 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* \brief STUN Support
|
||||
*
|
||||
* \author Mark Spencer <markster@digium.com>
|
||||
*
|
||||
* \note STUN is defined in RFC 3489.
|
||||
*/
|
||||
|
||||
#include "asterisk.h"
|
||||
|
||||
ASTERISK_FILE_VERSION(__FILE__, "$Revision: 124370 $")
|
||||
|
||||
#include "asterisk/_private.h"
|
||||
#include "asterisk/stun.h"
|
||||
#include "asterisk/cli.h"
|
||||
#include "asterisk/utils.h"
|
||||
#include "asterisk/channel.h"
|
||||
|
||||
static int stundebug; /*!< Are we debugging stun? */
|
||||
|
||||
/*!
|
||||
* \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));
|
||||
|
||||
/*! \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 *sin, 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 = sin->sin_port;
|
||||
addr->addr = sin->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();
|
||||
}
|
||||
|
||||
/*! \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)
|
||||
{
|
||||
struct stun_header *hdr = (struct stun_header *)data;
|
||||
struct stun_attr *attr;
|
||||
struct stun_state st;
|
||||
int ret = AST_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 = AST_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));
|
||||
ast_stun_handle_packet(s, &src, reply_buf, res,
|
||||
stun_get_mapped, answer);
|
||||
res = 0; /* signal regular exit */
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static char *handle_cli_stun_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
||||
{
|
||||
switch (cmd) {
|
||||
case CLI_INIT:
|
||||
e->command = "stun set debug {on|off}";
|
||||
e->usage =
|
||||
"Usage: stun set debug {on|off}\n"
|
||||
" Enable/Disable STUN (Simple Traversal of UDP through NATs)\n"
|
||||
" debugging\n";
|
||||
return NULL;
|
||||
case CLI_GENERATE:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (a->argc != e->args)
|
||||
return CLI_SHOWUSAGE;
|
||||
|
||||
if (!strncasecmp(a->argv[e->args-1], "on", 2))
|
||||
stundebug = 1;
|
||||
else if (!strncasecmp(a->argv[e->args-1], "off", 3))
|
||||
stundebug = 0;
|
||||
else
|
||||
return CLI_SHOWUSAGE;
|
||||
|
||||
ast_cli(a->fd, "STUN Debugging %s\n", stundebug ? "Enabled" : "Disabled");
|
||||
return CLI_SUCCESS;
|
||||
}
|
||||
|
||||
static struct ast_cli_entry cli_stun[] = {
|
||||
AST_CLI_DEFINE(handle_cli_stun_set_debug, "Enable/Disable STUN debugging"),
|
||||
};
|
||||
|
||||
/*! \brief Initialize the STUN system in Asterisk */
|
||||
void ast_stun_init(void)
|
||||
{
|
||||
ast_cli_register_multiple(cli_stun, sizeof(cli_stun) / sizeof(struct ast_cli_entry));
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user