diff --git a/CHANGES b/CHANGES index 5857165c8d75e3a66d967b0243a95ae8c35af4b4..6032dd8a053a6471f9e436ce819a6687b4be5ab2 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,13 @@ ------------------------------------------------------------------------------ +res_pjsip +------------------ + * Added endpoint configuration parameter "preferred_codec_only". + This allow asterisk response to a SIP invite with the single most + preferred codec rather than advertising all joint codec capabilities. + This limits the other side's codec choice to exactly what we prefer. + ------------------------------------------------------------------------------ --- Functionality changes from Asterisk 14.0.0 to Asterisk 14.1.0 ---------- ------------------------------------------------------------------------------ diff --git a/configs/samples/pjsip.conf.sample b/configs/samples/pjsip.conf.sample index 0d1c03909f1cf5154c97929f48e085a5d1581e99..e6b32495ba36f5864c41de7d143f24acec8f4725 100644 --- a/configs/samples/pjsip.conf.sample +++ b/configs/samples/pjsip.conf.sample @@ -764,6 +764,10 @@ ; "0" or not enabled) ;contact_user= ; On outgoing requests, force the user portion of the Contact ; header to this value (default: "") +;preferred_codec_only=yes ; Respond to a SIP invite with the single most preferred codec + ; rather than advertising all joint codec capabilities. This + ; limits the other side's codec choice to exactly what we prefer. + ; default is no. ;==========================AUTH SECTION OPTIONS========================= ;[auth] diff --git a/contrib/ast-db-manage/config/versions/7f3e21abe318_add_preferred_codec_only_option_to_pjsip.py b/contrib/ast-db-manage/config/versions/7f3e21abe318_add_preferred_codec_only_option_to_pjsip.py new file mode 100644 index 0000000000000000000000000000000000000000..083d08966e838c5dde0d2dc18a83b56df11e155a --- /dev/null +++ b/contrib/ast-db-manage/config/versions/7f3e21abe318_add_preferred_codec_only_option_to_pjsip.py @@ -0,0 +1,30 @@ +"""add preferred_codec_only option to pjsip + +Revision ID: 7f3e21abe318 +Revises: 4e2493ef32e6 +Create Date: 2016-09-02 11:00:23.534748 + +""" + +# revision identifiers, used by Alembic. +revision = '7f3e21abe318' +down_revision = '4e2493ef32e6' + +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.add_column('ps_endpoints', sa.Column('preferred_codec_only', yesno_values)) + +def downgrade(): + op.drop_column('ps_endpoints', 'preferred_codec_only') diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h index 4cede43919b3b9d770237393d4122f8c6a57792b..8a5ad29c59810d9f745320c0199d394ffdce59b8 100644 --- a/include/asterisk/res_pjsip.h +++ b/include/asterisk/res_pjsip.h @@ -757,6 +757,8 @@ struct ast_sip_endpoint { unsigned int faxdetect_timeout; /*! Override the user on the outgoing Contact header with this value. */ char *contact_user; + /*! Whether to response SDP offer with single most preferred codec. */ + unsigned int preferred_codec_only; }; /*! diff --git a/res/res_pjsip.c b/res/res_pjsip.c index 34edc8ca511ccd7e1e8c6fb12accadce4395afc0..7bb10c07f01b59035ebceca2653d6283f1f2181a 100644 --- a/res/res_pjsip.c +++ b/res/res_pjsip.c @@ -833,6 +833,9 @@ have this accountcode set on it. </para></description> </configOption> + <configOption name="preferred_codec_only" default="no"> + <synopsis>Respond to a SIP invite with the single most preferred codec rather than advertising all joint codec capabilities. This limits the other side's codec choice to exactly what we prefer.</synopsis> + </configOption> <configOption name="rtp_keepalive"> <synopsis>Number of seconds between RTP comfort noise keepalive packets.</synopsis> <description><para> @@ -2022,6 +2025,9 @@ <parameter name="Accountcode"> <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='accountcode']/synopsis/node())"/></para> </parameter> + <parameter name="PreferredCodecOnly"> + <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='preferred_codec_only']/synopsis/node())"/></para> + </parameter> <parameter name="DeviceState"> <para>The aggregate device state for this endpoint.</para> </parameter> diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c index 333be71438a735b00fb0772a45f5b1ce71d7cb14..97c357a9e1ce61716c5fe65777dab618f72e5297 100644 --- a/res/res_pjsip/pjsip_configuration.c +++ b/res/res_pjsip/pjsip_configuration.c @@ -1933,6 +1933,7 @@ int ast_res_pjsip_initialize_configuration(void) ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "contact_acl", "", endpoint_acl_handler, contact_acl_to_str, NULL, 0, 0); ast_sorcery_object_field_register(sip_sorcery, "endpoint", "subscribe_context", "", OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct ast_sip_endpoint, subscription.context)); ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "contact_user", "", contact_user_handler, contact_user_to_str, NULL, 0, 0); + ast_sorcery_object_field_register(sip_sorcery, "endpoint", "preferred_codec_only", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, preferred_codec_only)); if (ast_sip_initialize_sorcery_transport()) { ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n"); diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c index 6610ef126c365f3358c2c86a1472920e226780ff..68d5fdb56389211bcd1cc4d6b8e8a37087a4d882 100644 --- a/res/res_pjsip_sdp_rtp.c +++ b/res/res_pjsip_sdp_rtp.c @@ -360,8 +360,13 @@ static int set_caps(struct ast_sip_session *session, ast_format_cap_append_from_cap(caps, ast_channel_nativeformats(session->channel), AST_MEDIA_TYPE_UNKNOWN); ast_format_cap_remove_by_type(caps, media_type); - ast_format_cap_append_from_cap(caps, joint, media_type); - + if (session->endpoint->preferred_codec_only){ + struct ast_format *preferred_fmt = ast_format_cap_get_format(joint, 0); + ast_format_cap_append(caps, preferred_fmt, 0); + ao2_ref(preferred_fmt, -1); + } else { + ast_format_cap_append_from_cap(caps, joint, media_type); + } /* * Apply the new formats to the channel, potentially changing * raw read/write formats and translation path while doing so. diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c index 315393fdb895e6005eddedfd1c99cce72c2da0e2..0ab45c74e1306e5a8f8f9a5797639e28efbb7b96 100644 --- a/res/res_pjsip_session.c +++ b/res/res_pjsip_session.c @@ -1247,7 +1247,9 @@ int ast_sip_session_create_invite(struct ast_sip_session *session, pjsip_tx_data pjsip_inv_set_local_sdp(session->inv_session, offer); pjmedia_sdp_neg_set_prefer_remote_codec_order(session->inv_session->neg, PJ_FALSE); #ifdef PJMEDIA_SDP_NEG_ANSWER_MULTIPLE_CODECS - pjmedia_sdp_neg_set_answer_multiple_codecs(session->inv_session->neg, PJ_TRUE); + if (!session->endpoint->preferred_codec_only) { + pjmedia_sdp_neg_set_answer_multiple_codecs(session->inv_session->neg, PJ_TRUE); + } #endif /* @@ -2141,7 +2143,9 @@ static int new_invite(void *data) 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 - pjmedia_sdp_neg_set_answer_multiple_codecs(invite->session->inv_session->neg, PJ_TRUE); + if (!invite->session->endpoint->preferred_codec_only) { + pjmedia_sdp_neg_set_answer_multiple_codecs(invite->session->inv_session->neg, PJ_TRUE); + } #endif }