[Asterisk-code-review] chan_pjsip: Add pjsip option for moh allows only answered channel (asterisk[master])
Sungtae Kim
asteriskteam at digium.com
Sat Jul 9 03:10:31 CDT 2022
Sungtae Kim has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/18781 )
Change subject: chan_pjsip: Add pjsip option for moh allows only answered channel
......................................................................
chan_pjsip: Add pjsip option for moh allows only answered channel
This change adds an option, moh_answredonly, that when enabled will
process the hold request when the channel is answered.
Change-Id: I3c9b9101e4dc85338154b8004cecdd3edc227474
---
M channels/chan_pjsip.c
M configs/samples/pjsip.conf.sample
A contrib/ast-db-manage/config/versions/f407f42473e5_add_moh_answeredonly_option_to_pjsip.py
M include/asterisk/res_pjsip.h
M include/asterisk/res_pjsip_session.h
M res/res_pjsip/pjsip_config.xml
M res/res_pjsip/pjsip_configuration.c
M res/res_pjsip/pjsip_manager.xml
M res/res_pjsip_session.c
9 files changed, 54 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/81/18781/1
diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index 07b9088..1afa741 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -1767,6 +1767,12 @@
}
break;
case AST_CONTROL_HOLD:
+ if (channel->session->moh_answeredonly && (ast_channel_state(ast) == AST_STATE_UP)) {
+ ast_log(LOG_DEBUG, "The session '%s' is not able to oh hold with endpoint '%s'.\n",
+ ast_sorcery_object_get_id(channel->session),
+ ast_sorcery_object_get_id(channel->session->endpoint));
+ break;
+ }
chan_pjsip_add_hold(ast_channel_uniqueid(ast));
device_buf_size = strlen(ast_channel_name(ast)) + 1;
device_buf = alloca(device_buf_size);
diff --git a/configs/samples/pjsip.conf.sample b/configs/samples/pjsip.conf.sample
index 9d73843..fa77873 100644
--- a/configs/samples/pjsip.conf.sample
+++ b/configs/samples/pjsip.conf.sample
@@ -675,6 +675,7 @@
;moh_suggest=default ; Default Music On Hold class (default: "default")
;moh_passthrough=yes ; Pass Music On Hold through using SIP re-invites with sendonly
; when placing on hold and sendrecv when taking off hold
+;moh_answeredonly=yes ; Allows the only answered channel able to be music on hold.
;outbound_auth= ; Authentication object used for outbound requests (default:
; "")
;outbound_proxy= ; Proxy through which to send requests, a full SIP URI
diff --git a/contrib/ast-db-manage/config/versions/f407f42473e5_add_moh_answeredonly_option_to_pjsip.py b/contrib/ast-db-manage/config/versions/f407f42473e5_add_moh_answeredonly_option_to_pjsip.py
new file mode 100644
index 0000000..d67acc7
--- /dev/null
+++ b/contrib/ast-db-manage/config/versions/f407f42473e5_add_moh_answeredonly_option_to_pjsip.py
@@ -0,0 +1,35 @@
+"""add_moh_answeredonly_option_to_pjsip
+
+Revision ID: f407f42473e5
+Revises: 58e440314c2a
+Create Date: 2022-07-09 15:13:20.273405
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = 'f407f42473e5'
+down_revision = '58e440314c2a'
+
+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('moh_answeredonly', yesno_values))
+
+
+def downgrade():
+ if op.get_context().bind.dialect.name == 'mssql':
+ op.drop_constraint('ck_ps_endpoints_moh_answeredonly_yesno_values','ps_endpoints')
+ with op.batch_alter_table('ps_endpoints') as batch_op:
+ batch_op.drop_column('moh_answeredonly')
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index b5b5a72..06db799 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -931,6 +931,8 @@
unsigned int usereqphone;
/*! Whether to pass through hold and unhold using re-invites with recvonly and sendrecv */
unsigned int moh_passthrough;
+ /*! Allows the only answered channel able to be music on hold */
+ unsigned int moh_answeredonly;
/*! Access control list */
struct ast_acl_list *acl;
/*! Restrict what IPs are allowed in the Contact header (for registration) */
diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h
index 49e6007..f6d65dd 100644
--- a/include/asterisk/res_pjsip_session.h
+++ b/include/asterisk/res_pjsip_session.h
@@ -229,6 +229,8 @@
unsigned int ended_while_deferred:1;
/*! Whether to pass through hold and unhold using re-invites with recvonly and sendrecv */
unsigned int moh_passthrough:1;
+ /*! Allows the only answered channel able to be music on hold */
+ unsigned int moh_answeredonly:1;
/*! DTMF mode to use with this session, from endpoint but can change */
enum ast_sip_dtmf_mode dtmf;
/*! Initial incoming INVITE Request-URI. NULL otherwise. */
diff --git a/res/res_pjsip/pjsip_config.xml b/res/res_pjsip/pjsip_config.xml
index e6fca2e..7003394 100644
--- a/res/res_pjsip/pjsip_config.xml
+++ b/res/res_pjsip/pjsip_config.xml
@@ -943,6 +943,9 @@
<configOption name="moh_passthrough" default="no">
<synopsis>Determines whether hold and unhold will be passed through using re-INVITEs with recvonly and sendrecv to the remote side</synopsis>
</configOption>
+ <configOption name="moh_answeredonly" default="no">
+ <synopsis>Allows the only answered channel able to be music on hold</synopsis>
+ </configOption>
<configOption name="sdp_owner" default="-">
<synopsis>String placed as the username portion of an SDP origin (o=) line.</synopsis>
</configOption>
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index ace68d2..bbe8033 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -2123,6 +2123,7 @@
ast_sorcery_object_field_register(sip_sorcery, "endpoint", "allow_transfer", "yes", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, allowtransfer));
ast_sorcery_object_field_register(sip_sorcery, "endpoint", "user_eq_phone", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, usereqphone));
ast_sorcery_object_field_register(sip_sorcery, "endpoint", "moh_passthrough", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, moh_passthrough));
+ ast_sorcery_object_field_register(sip_sorcery, "endpoint", "moh_answeredonly", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, moh_answeredonly));
ast_sorcery_object_field_register(sip_sorcery, "endpoint", "sdp_owner", "-", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, media.sdpowner));
ast_sorcery_object_field_register(sip_sorcery, "endpoint", "sdp_session", "Asterisk", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, media.sdpsession));
ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "tos_audio", "0", tos_handler, tos_audio_to_str, NULL, 0, 0);
diff --git a/res/res_pjsip/pjsip_manager.xml b/res/res_pjsip/pjsip_manager.xml
index 810a5e3..c03c25c 100644
--- a/res/res_pjsip/pjsip_manager.xml
+++ b/res/res_pjsip/pjsip_manager.xml
@@ -417,6 +417,9 @@
<parameter name="MohPassthrough">
<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='moh_passthrough']/synopsis/node())"/></para>
</parameter>
+ <parameter name="MohAnsweredOnly">
+ <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='moh_answeredonly']/synopsis/node())"/></para>
+ </parameter>
<parameter name="SdpOwner">
<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='sdp_owner']/synopsis/node())"/></para>
</parameter>
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index d4a857f..9051b48 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -3090,6 +3090,7 @@
session->dtmf = endpoint->dtmf;
session->moh_passthrough = endpoint->moh_passthrough;
+ session->moh_answeredonly = endpoint->moh_answeredonly;
if (ast_sip_session_add_supplements(session)) {
/* Release the ref held by session->inv_session */
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18781
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I3c9b9101e4dc85338154b8004cecdd3edc227474
Gerrit-Change-Number: 18781
Gerrit-PatchSet: 1
Gerrit-Owner: Sungtae Kim <pchero21 at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220709/103261f7/attachment.html>
More information about the asterisk-code-review
mailing list