summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--channels/chan_sip.c2
-rw-r--r--contrib/ast-db-manage/config/versions/1d0e332c32af_create_rls_table.py39
-rw-r--r--include/asterisk/rtp_engine.h6
-rw-r--r--main/rtp_engine.c15
-rw-r--r--res/res_hep.c34
-rw-r--r--res/res_pjsip_sdp_rtp.c18
-rw-r--r--res/res_pjsip_session.c137
7 files changed, 169 insertions, 82 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index affe937e8..6fd7e8634 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -13097,7 +13097,7 @@ static void add_codec_to_sdp(const struct sip_pvt *p,
/* Opus mandates 2 channels in rtpmap */
if (ast_format_cmp(format, ast_format_opus) == AST_FORMAT_CMP_EQUAL) {
ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%u/2\r\n", rtp_code, mime, rate);
- } else if ((35 <= rtp_code) || !(sip_cfg.compactheaders)) {
+ } else if ((AST_RTP_PT_LAST_STATIC < rtp_code) || !(sip_cfg.compactheaders)) {
ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%u\r\n", rtp_code, mime, rate);
}
diff --git a/contrib/ast-db-manage/config/versions/1d0e332c32af_create_rls_table.py b/contrib/ast-db-manage/config/versions/1d0e332c32af_create_rls_table.py
new file mode 100644
index 000000000..3557f0d52
--- /dev/null
+++ b/contrib/ast-db-manage/config/versions/1d0e332c32af_create_rls_table.py
@@ -0,0 +1,39 @@
+"""create rls table
+
+Revision ID: 1d0e332c32af
+Revises: 2da192dbbc65
+Create Date: 2017-04-25 12:50:09.412662
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '1d0e332c32af'
+down_revision = '2da192dbbc65'
+
+from alembic import op
+import sqlalchemy as sa
+from sqlalchemy.dialects.postgresql import ENUM
+
+YESNO_NAME = 'yesno_values'
+YESNO_VALUES = ['yes', 'no']
+
+def upgrade():
+ ############################# Enums ##############################
+
+ # yesno_values have already been created, so use postgres enum object
+ # type to get around "already created" issue - works okay with mysql
+ yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=False)
+
+ op.create_table(
+ 'ps_resource_list',
+ sa.Column('id', sa.String(40), nullable=False, unique=True),
+ sa.Column('list_item', sa.String(2048)),
+ sa.Column('event', sa.String(40)),
+ sa.Column('full_state', yesno_values),
+ sa.Column('notification_batch_interval', sa.Integer),
+ )
+
+ op.create_index('ps_resource_list_id', 'ps_resource_list', ['id'])
+
+def downgrade():
+ op.drop_table('ps_resource_list')
diff --git a/include/asterisk/rtp_engine.h b/include/asterisk/rtp_engine.h
index fa7fed8a1..55acf6529 100644
--- a/include/asterisk/rtp_engine.h
+++ b/include/asterisk/rtp_engine.h
@@ -81,6 +81,12 @@ extern "C" {
/*! Maximum number of payload types RTP can support. */
#define AST_RTP_MAX_PT 128
+/*!
+ * Last RTP payload type statically assigned, see
+ * http://www.iana.org/assignments/rtp-parameters
+ */
+#define AST_RTP_PT_LAST_STATIC 34
+
/*! First dynamic RTP payload type */
#define AST_RTP_PT_FIRST_DYNAMIC 96
diff --git a/main/rtp_engine.c b/main/rtp_engine.c
index 0a2e84fcd..82298901d 100644
--- a/main/rtp_engine.c
+++ b/main/rtp_engine.c
@@ -1426,28 +1426,31 @@ static int find_unused_payload(const struct ast_rtp_codecs *codecs)
* https://tools.ietf.org/html/draft-roach-mmusic-unified-plan#section-3.2.1.2
* https://tools.ietf.org/html/draft-wu-avtcore-dynamic-pt-usage#section-3
*/
- res = find_unused_payload_in_range(codecs, MAX(ast_option_rtpptdynamic, 35),
+ res = find_unused_payload_in_range(
+ codecs, MAX(ast_option_rtpptdynamic, AST_RTP_PT_LAST_STATIC + 1),
AST_RTP_PT_LAST_REASSIGN, static_RTP_PT);
if (res != -1) {
return res;
}
- /* Yet, reusing mappings below 35 is not supported in Asterisk because
- * when Compact Headers are activated, no rtpmap is send for those below
- * 35. If you want to use 35 and below
+ /* Yet, reusing mappings below AST_RTP_PT_LAST_STATIC (35) is not supported
+ * in Asterisk because when Compact Headers are activated, no rtpmap is
+ * send for those below 35. If you want to use 35 and below
* A) do not use Compact Headers,
* B) remove that code in chan_sip/res_pjsip, or
* C) add a flag that this RTP Payload Type got reassigned dynamically
* and requires a rtpmap even with Compact Headers enabled.
*/
res = find_unused_payload_in_range(
- codecs, MAX(ast_option_rtpptdynamic, 20), 35, static_RTP_PT);
+ codecs, MAX(ast_option_rtpptdynamic, 20),
+ AST_RTP_PT_LAST_STATIC + 1, static_RTP_PT);
if (res != -1) {
return res;
}
return find_unused_payload_in_range(
- codecs, MAX(ast_option_rtpptdynamic, 0), 20, static_RTP_PT);
+ codecs, MAX(ast_option_rtpptdynamic, 0),
+ 20, static_RTP_PT);
}
/*!
diff --git a/res/res_hep.c b/res/res_hep.c
index 41a558141..25b4d13b1 100644
--- a/res/res_hep.c
+++ b/res/res_hep.c
@@ -69,7 +69,7 @@
</enumlist>
</description>
</configOption>
- <configOption name="capture_address" default="192.168.1.1:9061">
+ <configOption name="capture_address">
<synopsis>The address and port of the Homer server to send packets to.</synopsis>
</configOption>
<configOption name="capture_password">
@@ -96,8 +96,6 @@
#include <netinet/udp.h>
#include <netinet/ip6.h>
-#define DEFAULT_HEP_SERVER ""
-
/*! Generic vendor ID. Used for HEPv3 standard packets */
#define GENERIC_VENDOR_ID 0x0000
@@ -280,11 +278,13 @@ static AO2_GLOBAL_OBJ_STATIC(global_data);
static struct ast_taskprocessor *hep_queue_tp;
static void *module_config_alloc(void);
+static int hepv3_config_pre_apply(void);
static void hepv3_config_post_apply(void);
/*! \brief Register information about the configs being processed by this module */
CONFIG_INFO_STANDARD(cfg_info, global_config, module_config_alloc,
.files = ACO_FILES(&hepv3_conf),
+ .pre_apply_config = hepv3_config_pre_apply,
.post_apply_config = hepv3_config_post_apply,
);
@@ -377,6 +377,8 @@ static struct hepv3_runtime_data *hepv3_data_alloc(struct hepv3_global_config *c
return NULL;
}
+ data->sockfd = -1;
+
if (!ast_sockaddr_parse(&data->remote_addr, config->capture_address, PARSE_PORT_REQUIRE)) {
ast_log(AST_LOG_WARNING, "Failed to create address from %s\n", config->capture_address);
ao2_ref(data, -1);
@@ -594,11 +596,33 @@ int hepv3_send_packet(struct hepv3_capture_info *capture_info)
}
/*!
+ * \brief Pre-apply callback for the config framework.
+ *
+ * This validates that required fields exist and are populated.
+ */
+static int hepv3_config_pre_apply(void)
+{
+ struct module_config *config = aco_pending_config(&cfg_info);
+
+ if (!config->general->enabled) {
+ /* If we're not enabled, we don't care about anything else */
+ return 0;
+ }
+
+ if (ast_strlen_zero(config->general->capture_address)) {
+ ast_log(AST_LOG_ERROR, "Missing required configuration option 'capture_address'\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*!
* \brief Post-apply callback for the config framework.
*
* This will create the run-time information from the supplied
* configuration.
-*/
+ */
static void hepv3_config_post_apply(void)
{
RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(global_config), ao2_cleanup);
@@ -653,7 +677,7 @@ static int load_module(void)
}
aco_option_register(&cfg_info, "enabled", ACO_EXACT, global_options, "yes", OPT_BOOL_T, 1, FLDSET(struct hepv3_global_config, enabled));
- aco_option_register(&cfg_info, "capture_address", ACO_EXACT, global_options, DEFAULT_HEP_SERVER, OPT_STRINGFIELD_T, 0, STRFLDSET(struct hepv3_global_config, capture_address));
+ aco_option_register(&cfg_info, "capture_address", ACO_EXACT, global_options, "", OPT_STRINGFIELD_T, 1, STRFLDSET(struct hepv3_global_config, capture_address));
aco_option_register(&cfg_info, "capture_password", ACO_EXACT, global_options, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct hepv3_global_config, capture_password));
aco_option_register(&cfg_info, "capture_id", ACO_EXACT, global_options, "0", OPT_UINT_T, 0, STRFLDSET(struct hepv3_global_config, capture_id));
aco_option_register_custom(&cfg_info, "uuid_type", ACO_EXACT, global_options, "call-id", uuid_type_handler, 0);
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index dfa6957c7..97e365c10 100644
--- a/res/res_pjsip_sdp_rtp.c
+++ b/res/res_pjsip_sdp_rtp.c
@@ -453,6 +453,7 @@ static int set_caps(struct ast_sip_session *session,
static pjmedia_sdp_attr* generate_rtpmap_attr(struct ast_sip_session *session, pjmedia_sdp_media *media, pj_pool_t *pool,
int rtp_code, int asterisk_format, struct ast_format *format, int code)
{
+ extern pj_bool_t pjsip_use_compact_form;
pjmedia_sdp_rtpmap rtpmap;
pjmedia_sdp_attr *attr = NULL;
char tmp[64];
@@ -461,6 +462,11 @@ static pjmedia_sdp_attr* generate_rtpmap_attr(struct ast_sip_session *session, p
snprintf(tmp, sizeof(tmp), "%d", rtp_code);
pj_strdup2(pool, &media->desc.fmt[media->desc.fmt_count++], tmp);
+
+ if (rtp_code <= AST_RTP_PT_LAST_STATIC && pjsip_use_compact_form) {
+ return NULL;
+ }
+
rtpmap.pt = media->desc.fmt[media->desc.fmt_count - 1];
rtpmap.clock_rate = ast_rtp_lookup_sample_rate2(asterisk_format, format, code);
pj_strdup2(pool, &rtpmap.enc_name, ast_rtp_lookup_mime_subtype2(asterisk_format, format, code, options));
@@ -1260,11 +1266,9 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
continue;
}
- if (!(attr = generate_rtpmap_attr(session, media, pool, rtp_code, 1, format, 0))) {
- ao2_ref(format, -1);
- continue;
+ if ((attr = generate_rtpmap_attr(session, media, pool, rtp_code, 1, format, 0))) {
+ media->attr[media->attr_count++] = attr;
}
- media->attr[media->attr_count++] = attr;
if ((attr = generate_fmtp_attr(pool, format, rtp_code))) {
media->attr[media->attr_count++] = attr;
@@ -1293,12 +1297,10 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
continue;
}
- if (!(attr = generate_rtpmap_attr(session, media, pool, rtp_code, 0, NULL, index))) {
- continue;
+ if ((attr = generate_rtpmap_attr(session, media, pool, rtp_code, 0, NULL, index))) {
+ media->attr[media->attr_count++] = attr;
}
- media->attr[media->attr_count++] = attr;
-
if (index == AST_RTP_DTMF) {
snprintf(tmp, sizeof(tmp), "%d 0-16", rtp_code);
attr = pjmedia_sdp_attr_create(pool, "fmtp", pj_cstr(&stmp, tmp));
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 560b3903d..3034652a5 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -1328,9 +1328,7 @@ static void session_destructor(void *obj)
ao2_cleanup(session->req_caps);
ao2_cleanup(session->direct_media_cap);
- if (session->dsp) {
- ast_dsp_free(session->dsp);
- }
+ ast_dsp_free(session->dsp);
if (session->inv_session) {
pjsip_dlg_dec_session(session->inv_session->dlg, &session_module);
@@ -1400,6 +1398,7 @@ struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint,
struct ast_sip_contact *contact, pjsip_inv_session *inv_session, pjsip_rx_data *rdata)
{
RAII_VAR(struct ast_sip_session *, session, NULL, ao2_cleanup);
+ struct ast_sip_session *ret_session;
struct ast_sip_session_supplement *iter;
int dsp_features = 0;
@@ -1407,12 +1406,39 @@ struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint,
if (!session) {
return NULL;
}
+
AST_LIST_HEAD_INIT(&session->supplements);
+ AST_LIST_HEAD_INIT_NOLOCK(&session->delayed_requests);
+ ast_party_id_init(&session->id);
+
+ session->direct_media_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ if (!session->direct_media_cap) {
+ return NULL;
+ }
+ session->req_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ if (!session->req_caps) {
+ return NULL;
+ }
session->datastores = ao2_container_alloc(DATASTORE_BUCKETS, datastore_hash, datastore_cmp);
if (!session->datastores) {
return NULL;
}
+ if (endpoint->dtmf == AST_SIP_DTMF_INBAND || endpoint->dtmf == AST_SIP_DTMF_AUTO) {
+ dsp_features |= DSP_FEATURE_DIGIT_DETECT;
+ }
+ if (endpoint->faxdetect) {
+ dsp_features |= DSP_FEATURE_FAX_DETECT;
+ }
+ if (dsp_features) {
+ session->dsp = ast_dsp_new();
+ if (!session->dsp) {
+ return NULL;
+ }
+
+ ast_dsp_set_features(session->dsp, dsp_features);
+ }
+
session->endpoint = ao2_bump(endpoint);
session->media = ao2_container_alloc(MEDIA_BUCKETS, session_media_hash, session_media_cmp);
@@ -1449,30 +1475,6 @@ struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint,
inv_session->mod_data[session_module.id] = ao2_bump(session);
session->contact = ao2_bump(contact);
session->inv_session = inv_session;
- session->req_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
- if (!session->req_caps) {
- /* Release the ref held by session->inv_session */
- ao2_ref(session, -1);
- return NULL;
- }
-
- if ((endpoint->dtmf == AST_SIP_DTMF_INBAND) || (endpoint->dtmf == AST_SIP_DTMF_AUTO)) {
- dsp_features |= DSP_FEATURE_DIGIT_DETECT;
- }
-
- if (endpoint->faxdetect) {
- dsp_features |= DSP_FEATURE_FAX_DETECT;
- }
-
- if (dsp_features) {
- if (!(session->dsp = ast_dsp_new())) {
- /* Release the ref held by session->inv_session */
- ao2_ref(session, -1);
- return NULL;
- }
-
- ast_dsp_set_features(session->dsp, dsp_features);
- }
if (add_supplements(session)) {
/* Release the ref held by session->inv_session */
@@ -1484,11 +1486,11 @@ struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint,
iter->session_begin(session);
}
}
- session->direct_media_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
- AST_LIST_HEAD_INIT_NOLOCK(&session->delayed_requests);
- ast_party_id_init(&session->id);
- ao2_ref(session, +1);
- return session;
+
+ /* Avoid unnecessary ref manipulation to return a session */
+ ret_session = session;
+ session = NULL;
+ return ret_session;
}
/*! \brief struct controlling the suspension of the session's serializer. */
@@ -1704,6 +1706,7 @@ struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint
pjsip_dialog *dlg;
struct pjsip_inv_session *inv_session;
RAII_VAR(struct ast_sip_session *, session, NULL, ao2_cleanup);
+ struct ast_sip_session *ret_session;
/* If no location has been provided use the AOR list from the endpoint itself */
if (location || !contact) {
@@ -1760,14 +1763,17 @@ struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint
if (ast_format_cap_count(req_caps)) {
/* get joint caps between req_caps and endpoint caps */
struct ast_format_cap *joint_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
- ast_format_cap_get_compatible(req_caps, session->endpoint->media.codecs, joint_caps);
+
+ ast_format_cap_get_compatible(req_caps, endpoint->media.codecs, joint_caps);
/* if joint caps */
if (ast_format_cap_count(joint_caps)) {
/* copy endpoint caps into session->req_caps */
- ast_format_cap_append_from_cap(session->req_caps, session->endpoint->media.codecs, AST_MEDIA_TYPE_UNKNOWN);
+ ast_format_cap_append_from_cap(session->req_caps,
+ endpoint->media.codecs, AST_MEDIA_TYPE_UNKNOWN);
/* replace instances of joint caps equivalents in session->req_caps */
- ast_format_cap_replace_from_cap(session->req_caps, joint_caps, AST_MEDIA_TYPE_UNKNOWN);
+ ast_format_cap_replace_from_cap(session->req_caps, joint_caps,
+ AST_MEDIA_TYPE_UNKNOWN);
}
ao2_cleanup(joint_caps);
}
@@ -1781,8 +1787,10 @@ struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint
return NULL;
}
- ao2_ref(session, +1);
- return session;
+ /* Avoid unnecessary ref manipulation to return a session */
+ ret_session = session;
+ session = NULL;
+ return ret_session;
}
void ast_sip_session_terminate(struct ast_sip_session *session, int response)
@@ -2142,12 +2150,29 @@ static int new_invite(void *data)
goto end;
};
- if ((sdp_info = pjsip_rdata_get_sdp_info(invite->rdata)) && (sdp_info->sdp_err == PJ_SUCCESS) && sdp_info->sdp) {
+ pjsip_timer_setting_default(&timer);
+ timer.min_se = invite->session->endpoint->extensions.timer.min_se;
+ timer.sess_expires = invite->session->endpoint->extensions.timer.sess_expires;
+ pjsip_timer_init_session(invite->session->inv_session, &timer);
+
+ /*
+ * At this point, we've verified what we can that won't take awhile,
+ * so let's go ahead and send a 100 Trying out to stop any
+ * retransmissions.
+ */
+ if (pjsip_inv_initial_answer(invite->session->inv_session, invite->rdata, 100, NULL, NULL, &tdata) != PJ_SUCCESS) {
+ pjsip_inv_terminate(invite->session->inv_session, 500, PJ_TRUE);
+ goto end;
+ }
+ ast_sip_session_send_response(invite->session, tdata);
+
+ sdp_info = pjsip_rdata_get_sdp_info(invite->rdata);
+ if (sdp_info && (sdp_info->sdp_err == PJ_SUCCESS) && sdp_info->sdp) {
if (handle_incoming_sdp(invite->session, sdp_info->sdp)) {
- if (pjsip_inv_initial_answer(invite->session->inv_session, invite->rdata, 488, NULL, NULL, &tdata) == PJ_SUCCESS) {
+ tdata = NULL;
+ if (pjsip_inv_end_session(invite->session->inv_session, 488, NULL, &tdata) == PJ_SUCCESS
+ && tdata) {
ast_sip_session_send_response(invite->session, tdata);
- } else {
- pjsip_inv_terminate(invite->session->inv_session, 488, PJ_TRUE);
}
goto end;
}
@@ -2160,33 +2185,21 @@ static int new_invite(void *data)
/* If we were unable to create a local SDP terminate the session early, it won't go anywhere */
if (!local) {
- if (pjsip_inv_initial_answer(invite->session->inv_session, invite->rdata, 500, NULL, NULL, &tdata) == PJ_SUCCESS) {
+ tdata = NULL;
+ if (pjsip_inv_end_session(invite->session->inv_session, 500, NULL, &tdata) == PJ_SUCCESS
+ && tdata) {
ast_sip_session_send_response(invite->session, tdata);
- } else {
- pjsip_inv_terminate(invite->session->inv_session, 500, PJ_TRUE);
}
goto end;
- } else {
- pjsip_inv_set_local_sdp(invite->session->inv_session, local);
- pjmedia_sdp_neg_set_prefer_remote_codec_order(invite->session->inv_session->neg, PJ_FALSE);
-#ifdef PJMEDIA_SDP_NEG_ANSWER_MULTIPLE_CODECS
- if (!invite->session->endpoint->preferred_codec_only) {
- pjmedia_sdp_neg_set_answer_multiple_codecs(invite->session->inv_session->neg, PJ_TRUE);
- }
-#endif
}
- pjsip_timer_setting_default(&timer);
- timer.min_se = invite->session->endpoint->extensions.timer.min_se;
- timer.sess_expires = invite->session->endpoint->extensions.timer.sess_expires;
- pjsip_timer_init_session(invite->session->inv_session, &timer);
-
- /* At this point, we've verified what we can, so let's go ahead and send a 100 Trying out */
- if (pjsip_inv_initial_answer(invite->session->inv_session, invite->rdata, 100, NULL, NULL, &tdata) != PJ_SUCCESS) {
- pjsip_inv_terminate(invite->session->inv_session, 500, PJ_TRUE);
- goto end;
+ pjsip_inv_set_local_sdp(invite->session->inv_session, local);
+ pjmedia_sdp_neg_set_prefer_remote_codec_order(invite->session->inv_session->neg, PJ_FALSE);
+#ifdef PJMEDIA_SDP_NEG_ANSWER_MULTIPLE_CODECS
+ if (!invite->session->endpoint->preferred_codec_only) {
+ pjmedia_sdp_neg_set_answer_multiple_codecs(invite->session->inv_session->neg, PJ_TRUE);
}
- ast_sip_session_send_response(invite->session, tdata);
+#endif
handle_incoming_request(invite->session, invite->rdata);